[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: minor mkdir bug fixes
From: |
David Feuer |
Subject: |
Re: minor mkdir bug fixes |
Date: |
Wed, 15 Jun 2005 12:50:00 -0400 |
User-agent: |
Mutt/1.5.9i |
On Wed, Jun 15, 2005 at 01:52:25AM -0700, Paul Eggert wrote:
> address@hidden (David Feuer) writes:
> > In makepath.c:
> >
> > /* If we've saved the cwd and DIRPATH is an absolute pathname,
> > we must chdir to `/' in order to enable the chdir optimization.
> > So if chdir ("/") fails, turn off the optimization. */
> > if (do_chdir && *dirpath == '/' && chdir ("/") < 0)
> > do_chdir = false;
>
> Hmm, I didn't quite follow that. But the above code is somethign
> different. It says that paths like /a/b/c must be handled by first
> chdir("/"), whereas paths like a/b/c don't need that step.
>
> If it can't be chdir'ed into, then it can't be used at all, at least
> if traditional Unix semantics are used. (Or are you thinking ACLs?).
Sorry my original message was a bit unclear. The code above, checking
for the case of an absolute pathname, should be contrasted with the code
below:
/* If we were able to save the initial working directory,
then we can use chdir to change into each directory before
creating an entry in that directory. This avoids making
stat and mkdir process O(n^2) file name components. */
if (do_chdir && chdir (basename_dir) < 0)
{
error (0, errno, _("cannot chdir to directory %s"),
quote (dirpath));
CLEANUP;
return false;
}
The absolute pathname code seems to believe that it may be possible to
successfully make the directory even if it is impossible to chdir to /,
but this (main loop) code operates on the assumption that being unable
to chdir to a directory along the path is an unrecoverable error. Now I
suppose it's conceivable that in some system chdir treats the root
directory differently from other directories, but this seems unlikely.
If it is ever possible to create the directory when chdir fails, then
this latter (main loop) code should fall back on the unoptimized code
rather than aborting. Otherwise, the initial (absolute pathname) code
should be changed to abort. I hope that's a bit clearer.
David