[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: renameat
From: |
Jim Meyering |
Subject: |
Re: renameat |
Date: |
Fri, 02 Oct 2009 21:11:34 +0200 |
Eric Blake wrote:
...
> Subject: [PATCH] rename, fchdir: don't ignore chdir failure
>
> Although we just checked that chdir(cwd) worked, there is a
> race where it could disappear while we are temporarily away.
> If that happens, forcefully give up rather than proceeding
> in the wrong directory.
>
> * lib/fchdir.c (get_name): Abort on unexpected chdir failure.
> * lib/rename.c (rpl_rename) [W32]: Likewise.
> (rpl_rename) [RENAME_DEST_EXISTS_BUG]: Avoid one case of losing
> an empty destination directory if source cannot be renamed,
> although there is still possibility for failure.
> * doc/posix-functions/rename.texi (rename): Document the race.
> Reported by Jim Meyering.
...
Looks fine.
one nit
> diff --git a/doc/posix-functions/rename.texi b/doc/posix-functions/rename.texi
> index 65981db..be997aa 100644
> --- a/doc/posix-functions/rename.texi
> +++ b/doc/posix-functions/rename.texi
> @@ -27,7 +27,9 @@ rename
> @item
> This function will not always replace an existing destination on some
> platforms:
> -mingw.
> +Cygwin 1.5.x, mingw.
> +However, the replacement is not atomic for directories, and may end up
> +losing the empty destination if the source could not be renamed.
> @item
> This function mistakenly allows names ending in @samp{.} or @samp{..}
> on some platforms:
> diff --git a/lib/fchdir.c b/lib/fchdir.c
> index 54bbc62..e55ef6c 100644
> --- a/lib/fchdir.c
> +++ b/lib/fchdir.c
> @@ -106,7 +106,8 @@ get_name (char const *dir)
> return NULL;
> result = chdir (dir) ? NULL : getcwd (NULL, 0);
> saved_errno = errno;
> - chdir (cwd);
> + if (chdir (cwd))
> + abort ();
apparent unindent, due to TAB ;-)
(no big deal, of course)
...