# File path seems not compatible across windows and unix with save state

**URL:** <https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686>\
**Category:** Help!\
**Created:** [July 24, 2020, 3:46am UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686 "2020-07-24T03:46:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nxiao](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@nxiao](https://swi-prolog.discourse.group/u/nxiao)\
**Post date:** [July 24, 2020, 3:46am UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/1 "2020-07-24T03:46:23Z")

</div>

I’m using: SWI-Prolog version 8.3.3

1. rdf\_load from a folder /home/cocprd/cm/rdf3/ recursively.

2. First compiled prolog code on windows using:  
swipl -o willie -c abc.pl

3. copied willie to Linux, and run with:  
swipl -x willie

It seems converting file path to lower case.  
It works fine if compiling into saved state on Linux.

Error occurred - the file does exist by the name of /home/cocprd/cm/rdf3/kb/cyberobject/blue/ **Document** /001.cm  
(Document instead of document)

`’/home/cocprd/cm/rdf3/kb/cyberobject/blue/ **document** /001.cm’’ does not exist  
ERROR: In:  
ERROR: [37] time\_file(’/home/cocprd/cm/rdf3/kb/cyberobject/blue/ **document** /001.cm’,\_338)  
ERROR: [36] rdf\_db:open\_input\_if\_modified(file(’’),‘file:///home/cocprd/cm/rdf3/kb/cyberobject/blue/document/001.cm’,\_378,\_380,\_382,\_384,trig,[concurrent(1),…|…]) at /opt/prolog/lib/swipl/library/semweb/rdf\_db.pl:1806  
ERROR: [35] rdf\_db:rdf\_open\_input(‘file:///home/cocprd/cm/rdf3/kb/cyberobject/blue/ **document** /001.cm’,file(’’),‘file:///home/cocprd/cm/rdf3/kb/cyberobject/blue/document/001.cm’,\_450,\_452,\_454,trig,[concurrent(1),…|…]) at /opt/prolog/lib/swipl/library/semweb/rdf\_db.pl:1682  
ERROR: [34] rdf\_db:rdf\_load\_file((0xcd67530),’/home/cocprd/cm/rdf3/kb/cyberobject/blue/ **Document** /001.cm’,‘file:///home/cocprd/cm/rdf3/kb/cyberobject/blue/ **document** /001.cm’,file(’’),‘file:///home/cocprd/cm/rdf3/kb/cyberobject/blue/document/001.cm’,ip\_app\_load,[concurrent(1),…|…]) at /opt/prolog/lib/swipl/library/semweb/rdf\_db.pl:1555  
ERROR: [33] setup\_call\_catcher\_cleanup(rdf\_db:with\_mutex(rdf\_load\_file,…),rdf\_db:rdf\_load\_file((0xcd67530),’/home/cocprd/cm/rdf3/kb/cyberobject/blue/Document/001.cm’,‘file:///home/cocprd/cm/rdf3/kb/cyberobject/blue/document/001.cm’,…,‘file:///home/cocprd/cm/rdf3/kb/cyberobject/blue/document/001.cm’,ip\_app\_load,…),\_580,rdf\_db:rdf\_end\_load((0xcd67530))) at /opt/prolog/lib/swipl/boot/init.pl:562  
ERROR: [29] setup\_call\_catcher\_cleanup(rdf\_db:set\_prolog\_flag(agc\_margin,0),rdf\_db:rdf\_load\_noagc(’/home/cocprd/cm/rdf3/kb/cyberobject/blue/Document/001.cm’,ip\_app\_load,…),\_660,rdf\_db:set\_prolog\_flag(agc\_margin,10000)) at /opt/prolog/lib/swipl/boot/init.pl:562  
ERROR: [27] rdf\_db:rdf\_load(’/home/cocprd/cm/rdf3/kb/cyberobject/blue/ **Document** /001.cm’,’\<garbage\_collected\>’) at /opt/prolog/lib/swipl/library/semweb/rdf\_db.pl:1470

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 24, 2020, 7:52am UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/2 "2020-07-24T07:52:15Z")

</div>

True. Saved states are portable across platforms, but path names generally do not make sense and you thus need to avoid relying on them. There are more pitfalls, such as conditional compilation that may cause a state not to be suitable for the target platform. I don’t really see a solution to that. For the RDF store, the triples are not part of the state anyway and one should thus not load RDF while creating a saved program.

---

<div class="post-metadata">

**Author:** ![nxiao](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@nxiao](https://swi-prolog.discourse.group/u/nxiao)\
**Post date:** [July 24, 2020, 2:44pm UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/4 "2020-07-24T14:44:31Z")

</div>

Thanks Jan.  
First of all, I am not loading RDF into the saved state. RDF is being loaded at runtime using directory\_member/3 and rdf\_load/2.

Dig into it a bit more. Discovered the issue is with absolute\_file\_name/2,3 which is called by rdf\_load/2:  
On Windows:

?- absolute\_file\_name(’…/rdf3/kb/cyberobject/blue/Document/001.cm’, A,[]).  
A = ‘e:/project/rdf3/kb/cyberobject/blue/document/001.cm’.

On Linux:

?- absolute\_file\_name(’…/rdf3/cyberobject/Document/001.cm’, X, []).  
X = ‘/home/cocprd/cm/rdf3/cyberobject/Document/001.cm’.

As you have mentioned, there must be a conditional compilation for absolute\_file\_name/2,3. It breaks the portability here.

I don’t understand why it is needed to convert the case on path names. It seems to me that the issue of case on path names should be left to the underlying OS.

Lastly, I would like to argue that this need to be resolved. Most apps will read/write files and likely saved state portability will break in these cases unless stating only lower case path names are portable.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 25, 2020, 7:56am UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/5 "2020-07-25T07:56:12Z")

</div>

> [@nxiao](#):
>
> I don’t understand why it is needed to convert the case on path names.

Because SWI-Prolog tries to keep absolute file names such that name equality can be used to test whether we are talking about the same file. That may have been a dubious choice.

How does a saved absolute file name affect your saved state though? Of course absolute file names typically have changed in the target environment and should not be saved in the first place (or at least, the saved path should not be accessed).

---

<div class="post-metadata">

**Author:** ![nxiao](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@nxiao](https://swi-prolog.discourse.group/u/nxiao)\
**Post date:** [July 25, 2020, 1:11pm UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/6 "2020-07-25T13:11:32Z")

</div>

HI Jan,

I probably didn’t make myself clear.

I want to load rdf from a folder with sub-folders at runtime (part of initialization). I am using directory\_member/3 to traverse the folder recursively, use rdf\_load/2 to load the file with certain extensions.

The code snippet looks like:

```prolog
ip_load_app_kb(Dir) :-
    foreach(directory_member(Dir, F, [extensions([cm, trig, ttl])]), 
          rdf_load(F, []).

% the Dir come from the command line option.
: - ip_load_app_kb(Argv).

```

Say, I want to load from folder:  
in Windows: e:/project/app  
In Linux: /home/cocprd/app

Under the above folder:  
In Windows: e:/project/app/Document/001.cm  
In Linux: /home/cocprd/app/Document/001.cm

**Compile the code in windows. Run the saved state in Linux.**

It fails because the path name become **/home/cocprd/app/document/001.cm** instead of **/home/cocprd/app/Document/001.cm**. Linux path name is case sensitive thus couldn’t locate the file to load.

No absolute file name is stored in saved state, nor any RDFs. The intent is to load some RDFs from a folder when starting the app.

Hopefully this is clear enough.

Thanks, as always, a lot for your help.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 25, 2020, 1:25pm UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/7 "2020-07-25T13:25:08Z")

</div>

It is still not clear to me what is going wrong. Can you assemble a minimal program that I can really run?

One thing that comes to mind is the flag `file_name_case_handling`. Could it be that this is preserved in the state and thus set to the wrong value for Linux? I do not have access to a Windows machine right now …

If that is the problem, this flag probably needs to be added to the flags that should not be saved/restored in library(qsave).

---

<div class="post-metadata">

**Author:** ![nxiao](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@nxiao](https://swi-prolog.discourse.group/u/nxiao)\
**Post date:** [July 28, 2020, 3:12pm UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/8 "2020-07-28T15:12:25Z")

</div>

Hi Jan,

The flag **file\_name\_case\_handling** is what I am looking for. Thanks.

While setting the flag to case\_sensitive, swipl -o $$ -c $$ splits these messages:

```prolog
.....
Now c:/program files/swipl/library/apply.pl
Now c:/program files/swipl/library/apply.pl
Now c:/program files/swipl/library/date.pl
Now c:/program files/swipl/library/shell.pl
Now c:/program files/swipl/library/apply.pl
Now c:/program files/swipl/library/apply.pl
Now c:/program files/swipl/library/error.pl
Now c:/program files/swipl/library/lists.pl
Now c:/program files/swipl/library/pairs.pl
Now c:/program files/swipl/library/lists.pl
Now c:/program files/swipl/library/apply.pl
Now c:/program files/swipl/library/apply.pl
Now c:/program files/swipl/library/error.pl
Now c:/program files/swipl/library/lists.pl
Now c:/program files/swipl/library/lists.pl
Now c:/program files/swipl/library/process.pl
Now c:/program files/swipl/library/apply.pl
Now c:/program files/swipl/library/lists.pl
Now c:/program files/swipl/library/system.pl
% Disabled autoloading (loaded 17 files)
% Disabled autoloading (loaded 0 files)

```

In addition, the Disabled autoloading (loaded N files).  
N is different with flag file\_name\_case\_handling=case\_sensitive vs the default flag.

But it seems working okay.

Thank you!

Nan

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 29, 2020, 12:43pm UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/9 "2020-07-29T12:43:38Z")

</div>

Thanks for the update. Pushed a fix that disables saving this flag, so the state starts with the OS default rather than the OS default that created the state.

---

<div class="post-metadata">

**Author:** ![nxiao](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@nxiao](https://swi-prolog.discourse.group/u/nxiao)\
**Post date:** [July 29, 2020, 2:55pm UTC](https://swi-prolog.discourse.group/t/file-path-seems-not-compatible-across-windows-and-unix-with-save-state/2686/10 "2020-07-29T14:55:13Z")

</div>

COOOOL! Thanks!
