file:path-to-native() throws an error if its argument does not exist
I have a file:// URI that corresponds to a directory that I need to create (using svn mkdir, therefore file:create-dir() is not an option here) if it doesn’t exist. Calling file:path-to-native() on it results in a file:not-found error. Is there a fundamental reason why the file needs to exist before transforming its URI into the OS-native representation? Using BaseX 10.7.
Gerrit
Hi Gerrit,
If you don’t need the canonical path to a file resource on the file system, file:resolve-path may be the better choice. It can be used for both file URIs and local (relative or absolute) paths.
Hope this helps, Christian
Quoted text · le-tex · 11 lines
On Mon, Apr 22, 2024 at 8:00 AM Imsieke, Gerrit, le-tex < gerrit.imsieke at le-tex.de> wrote: > I have a file:// URI that corresponds to a directory that I need to create > (using svn mkdir, therefore file:create-dir() is not an option here) if it > doesn’t exist. Calling file:path-to-native() on it results in a > file:not-found error. Is there a fundamental reason why the file needs to > exist before transforming its URI into the OS-native representation? Using > BaseX 10.7. > > Gerrit >
Quoted text · le-tex · 7 lines
On Mon, 2024-04-22 at 08:00 +0200, Imsieke, Gerrit, le-tex wrote: > I have a file:// URI that corresponds to a directory that I need to > create (using svn mkdir, therefore file:create-dir() is not an option > here) if it doesn’t exist. Calling file:path-to-native() on it > results in a file:not-found error. Is there a fundamental reason why > the file needs to exist before transforming its URI into the OS- > native representation? Using BaseX 10.7.
First, as you prolly saw, the spec does say it's an error if the file does not exist.
Second, it behaves differently if it points to a directory than if it points to a file, and symbolic links are resolved.
But i agree there doesn't seem a reason for it to be an error if the file isn't there, except to the extent that it doesn't know whether to append the file separator for a directory...
It’s documented as non-deterministic, though, so that's OK.
liam
Quoted text · Imsieke, Gerrit, le-tex · 1 line
>
Thank you Christian, I should have read the description of file:resolve-path(). It does exactly what I need.
Gerrit
Quoted text · Christian Grün · 15 lines
On 22.04.2024 10:59, Christian Grün wrote: > Hi Gerrit, > > If you don’t need the canonical path to a file resource on the file system, file:resolve-path may be the better choice. It can be used for both file URIs and local (relative or absolute) paths. > > Hope this helps, > Christian > > > On Mon, Apr 22, 2024 at 8:00 AM Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de <mailto:gerrit.imsieke at le-tex.de>> wrote: > > I have a file:// URI that corresponds to a directory that I need to create (using svn mkdir, therefore file:create-dir() is not an option here) if it doesn’t exist. Calling file:path-to-native() on it results in a file:not-found error. Is there a fundamental reason why the file needs to exist before transforming its URI into the OS-native representation? Using BaseX 10.7. > > Gerrit >
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.