[Openmcl-devel] A platform independent pathname without truename

Pascal J. Bourguignon pjb at informatimago.com
Fri Jul 29 21:19:29 PDT 2011


Robert Goldman <rpgoldman at sift.info> writes:

> I always find that sooner or later I want to reference a pathname that
> has underscores in it, spaces, or something that otherwise breaks the
> rules of logical pathnames (which I can never adequately remember).

What? You cannot write a logical pathname translation?


> Sooner or later TRANSLATE-LOGICAL-PATHNAME goes pear-shaped and I rack
> my brains, then remember that I have done something bad again.  After
> that I find that the trouble I took to work with logical pathnames is
> all wasted, and rue my lot....

It's simple however.


> So now I try to just avoid the bloody things in favor of unix-style
> pathname strings, which seem to work everywhere as a de facto
> standard...  And I just use #+ to make sure I get either "/home" or
> "/Users" as appropriate....

Of course, it's an alternative.  A well written library to deal with
posix pathnames can be used.  After all, nowadays, there remain only
POSIX systems.



However, logical pathname are simple.  They are names that are used
logically.  Independently of their mapping to any real or ficticious
file system.

The rules are simple ("19.3.1 Syntax of Logical Pathname Namestrings").
Notably: 

   word---one or more uppercase letters, digits, and hyphens. 

You can write them with lower case letters, but a conforming
implementation must upper case them.

The mapping is specified independently from the logical pathnames.



If you want to access a file strangely named, (eg. a dot file), you need
to go thru a translation.

(setf (logical-pathname-translations "DOTFILES") nil
      (logical-pathname-translations "DOTFILES") 
      (list (list (make-pathname :host "DOTFILES"
                                 :directory '(:absolute)
                                 :name "MYAPP"
                                 :type "CONF")
                  (merge-pathnames #"./.my_app$!configuration file"
                                   (user-homedir-pathname) nil))))

So now on you can refer to the strangely named file as

    #P"DOTFILES:MYAPP.CONF"


What's even better: you don't need to specify the translations in your
program.  You can just use LOAD-LOGICAL-PATHNAME-TRANSLATIONS
and let the user specify the translations he wants.



Now, one thing logical pathnames are NOT designed for, is to access all
the files and directory of a messy file system.  For this, you need to
use:

1- implementation dependant features,
2- physical pathnames (which are implementation dependent).

So if you want to implement a mv(1) command in CL, to let the user
rename any file he wants, even '.Hello world.$.$.$', you can do it, but
only with implementation specific things (it may not be possible to do
it in all conforming implementations), and only using physical
pathnames.


But if you want to manage application resources in a plateform
independant ways, with logical pathnames you can do it easily.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.




More information about the Openmcl-devel mailing list