bug-coreutils
[Top][All Lists]
Advanced

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

Re: mv -f may remove the destination file


From: Paul Eggert
Subject: Re: mv -f may remove the destination file
Date: Thu, 05 May 2005 21:18:05 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Urs Thuermann <address@hidden> writes:

>     $ strace mv foo bar

Hmm, your email's "Subject:" line says "mv -f" but this strace doesn't.
I'll assume for now that you meant to write about plain "mv", not "mv -f".

>  lstat64("bar", 0xbffff904)          = -1 ENOENT (No such file or directory)
>  rename("foo", "bar")                = 0

> This check, however, is not sufficient as a file named bar could be
> created between the calls to lstat(2) and rename(2).

In general, mv is not (and is not supposed to be) immune to race
conditions like that.  If two processes are futzing around in the same
directory, bad things normally can happen with the standard utilities.
There are some exceptions, but this isn't one of them.

> If the source is not a directory, a better solution, suggested in
> comp.unix.internals, is to use link(2)

But POSIX requires "mv" to behave as if it called rename(), not link().
See <http://www.opengroup.org/onlinepubs/000095399/utilities/mv.html>.




reply via email to

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