3

I'm not new to Lisp but new to CL and a bit confused by the file and directory path handling. What I need: A completely cross-platform way to deal with file and directory paths that can be specified in URLs and stored in a database (preferably as text).

Current approach: Store a file path as a file URL using QURI, strictly with / Unix-style paths and serializable as URL strings. When I need local file access, these URL paths are translated to the local OS-specific file path. So I use UIOP:parse-unix-namestring to convert to a slash path and QURI to construct URLs.

Problem: The UIOP docs say that unix-namestring is not suitable for general platform-specific paths, and I need to convert the unix pathname to a string to store it in the DB. Moreover, most of the paths are going to be relative, but some of them could be absolute for external assets, and the UIOP docs also say that parse-unix-namestring is not suitable for absolute paths.

Questions: Every tutorial I've found recommends UIOP. But what's the right way of storing paths to folders and files in a cross-platform way in a database then? Am I about to do something horrible? Should I get rid of the idea of using URLs to store asset locations? It has the advantage to generalize nicely to other types of locations such as files on ftp and http servers. Am I safe if I make sure all paths are relative and proceed with using UIOP? Or, is there a better way to do this?

It's really important that this works on all kinds of (modern) file systems, with network volumes, etc.

  • I've investigated and it seems that URLs cannot deal with drive letters in a standard way, e.g. "file:///d:/some/path/test.txt" is not standard though accepted by many tools. QURI cannot process it, though, and UIOP unix paths cannot deal with this (since it's not really a Unix path, of course). So I guess I should not use URLs in general, or consider them to store partial information only. If I stick to relative paths only, my tool will not work with assets on other drives on Windows! – Eric '3ToedSloth' Oct 14 '21 at 16:22
  • You could look into `logical-pathname-translations`. Haven't really used it, but might help. – rajashekar Oct 14 '21 at 18:21
  • 1
    You probably do not want a 'completely cross-platform way of dealing with file and directory paths'. Where I live we represent our filenames with Bessel functions: probably you don't want that, I suspect. What is it, really, you *do* want? – ignis volens Oct 15 '21 at 19:46

0 Answers0