emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: file-truename, convert-standard-filename


From: Davis Herring
Subject: RE: file-truename, convert-standard-filename
Date: Fri, 26 Feb 2010 10:33:52 -0800 (PST)
User-agent: SquirrelMail/1.4.8-5.7.lanl7

[I was reading this old thread and thought I might provide my own useful
summary.]

> OK. Then add "and you do not know whether the file named exists" to what I
> wrote. Again, that is the general case.

I think too much attention is being paid to the question of whether files
exist, which adds noise because so often we don't know (in advance)
whether a particular file exists.

The simple explanation is this: out of the set of all possible strings,
some of them are valid filenames on a given platform/filesystem.  On GNU,
the only character that cannot occur in a filename is NUL, which is so
rarely considered that we say that the two sets (strings and valid
filenames) are the same.  On Windows, several common characters are
invalid: ? and * for instance.  (This is justified by the different rules
about wildcards in the common Windows shells.)  So there, the sets differ
substantially.  On DOS, things get even worse, because there are peculiar
restrictions on the use of . in filenames.  (It's not prohibited, but you
can only use one per path component, and it can't be the first character,
etc.)

When the user asks to visit a file, or we get a filename from `ls' or
whatever other system source, the distinction between these two sets is
unimportant, because system tools will only generate filenames in the
valid set, and reporting to the user that their filename is invalid is
sufficient (as they can then choose another).

However, when Emacs (or any of its libraries or extensions) picks a
filename, there is no intelligence that can react to an error when the
filename is invalid.  So we must plan ahead and have a mapping from the
set of strings to the (system-dependent) set of valid names.  That mapping
is `convert-standard-filename', and it is therefore necessary precisely
whenever it is Emacs itself that is choosing (or constructing, like the
`concat' examples) a filename.

The set of valid filenames is closed under the common operations on them
(like `file-name-directory', `file-relative-name', `expand-file-name',
`file-truename').  So once all agents picking filenames have chosen valid
ones, no invalid names will ever be generated from them, so
`convert-standard-filename' is never needed again.  This is why so many of
its uses are on literal strings; literals are the commonest way for Emacs
to "pick" filenames, and after that point it's unneeded.

It is of course true that an existing file must have a valid name, and an
invalid filename cannot name an existing file (since it can't even name a
nonexistent file, as one might create with `write-region').  But note that
nowhere in this exposition (outside of the introductory paragraph and this
one) is any mention made of whether files exist or not.

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]