Gnus development mailing list
 help / color / mirror / Atom feed
From: prj@po.cwru.edu (Paul Jarc)
Subject: Re: (concat "/dir/name/" "foo") --> (expand-file-name "foo" "/dir/name/")
Date: 22 Oct 2000 14:10:36 -0400	[thread overview]
Message-ID: <m3d7gs926l.fsf@multivac.student.cwru.edu> (raw)
In-Reply-To: Dave Love's message of "Sun, 22 Oct 2000 17:00:40 +0100"

Dave Love <d.love@dl.ac.uk> writes:
>  PJ> In each particular case of deciding whether to use
>  PJ> expand-file-name,
> 
> I don't think you should be making any such decision.

Let me rephrase.  Whether a filename is to be expanded should be a
documented part of any interface that uses filenames.  Expansion is
generally useful for users, so it would be done for most or all user
interfaces, but not necessarily for programmatic interfaces.  (This
has the cost that a user typically can't use a name like "foo/../bar"
literally when foo is a symlink, but we can live with that.)  Then
programs have to be careful to avoid, e.g., passing an expanded (or
not expanded) name to another interface that expects an unexpanded (or
expanded) name.  You want to avoid multiple expansions in general,
since expansion need not be idempotent, and you want to avoid
expanding a name which is known to be literal but which might invoke
magic - e.g., it came from directory-files - because its expansion
might be a different name, naming a different file.  So take a name
given by the user, expand it once, then keep that expanded name for
future use, and for building other filenames.  For example:
(setq expanded-name (expand-file-name directory-name-from-user)) ; once
(setq directory-name (file-name-as-directory expanded-name))     ; once
(concat directory-name literal-relative-name)                    ; whenever

Avoiding multiple expansions also helps with performance, regardless
of the correctness problems that might occur.

> If you think you should be able to suppress contraction of ../ for
> some reason, make a bug report with enough justification.  I'm not
> convinced.

../ was perhaps a bad example.  But I can't make a bug report, because
I haven't audited all the code that uses expand-file-name to see where
names might be expanded twice.  It would be easier and faster for the
various people who've written the code to audit it themselves, if they
hadn't thought of this issue when they wrote it.  Then they'll also be
more aware of the potential problem when they write new code.

> I doubt we've changed much significant in that area, but there is a
> tarball of a more recent version of the Lisp manual somewhere on
> alpha.gnu.org.

Got it, thanks.  Yes, I see that expand-file-name,
directory-file-name, and file-name-as-directory are subject to
handlers, so idempotency cannot be generally guaranteed.  It should
probably be a goal of any handler, though.


paul



  reply	other threads:[~2000-10-22 18:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-13 20:55 Kai Großjohann
2000-10-13 21:13 ` Paul Jarc
2000-10-13 22:19   ` Kai Großjohann
2000-10-16 18:12   ` Dave Love
2000-10-16 20:39     ` Paul Jarc
2000-10-16 22:36       ` Daniel Pittman
2000-10-18 17:55       ` Dave Love
2000-10-18 21:35         ` Paul Jarc
2000-10-22 16:00           ` Dave Love
2000-10-22 18:10             ` Paul Jarc [this message]
2000-10-22 18:51               ` Kai Großjohann
2000-10-23  0:45                 ` Paul Jarc
2000-10-23  7:52                   ` Kai Großjohann
2000-10-23 15:29                     ` Paul Jarc
2000-10-19  1:11         ` Daniel Pittman
2000-10-22 16:02           ` Dave Love

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3d7gs926l.fsf@multivac.student.cwru.edu \
    --to=prj@po.cwru.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).