When strace'ing GNU mv from fileutils-4.1 and from coreutils-5.2.1, I
see that mv checks with lstat(2) for the existance of the destination
file before calling rename(2) which would unlink the destination file:
$ strace mv foo bar
...
umask(0) = 022
stat64("bar", 0xbffffa38) = -1 ENOENT (No such file or directory)
brk(0x8053000) = 0x8053000
lstat64("foo", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
lstat64("bar", 0xbffff904) = -1 ENOENT (No such file or directory)
rename("foo", "bar") = 0
_exit(0) = ?
This check, however, is not sufficient as a file named bar could be
created between the calls to lstat(2) and rename(2). If the source is
not a directory, a better solution, suggested in comp.unix.internals,
is to use link(2)
if (link(old, new) == 0)
unlink(old);
urs
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils