2016-11-07 17:19:13 +0000, Geoff Clare: [...] > > Is that allowed by POSIX? > > No; the standard clearly says "The mv utility shall perform actions > equivalent to the rename() function" in step 3.
Well, when moving across file systems, it already does something very different from an atomic rename(), so it seems a bit artificial to mandate a rename() equivalent call for the same-fs moves. I suppose the issue with: if (link(a, b) fails) { if (error was EEXIST) { prompt user; if (yes) { rename(a, b); } } else die; } else { unlink(a); } is that we could unlink a different "a" file (like if someone does a rename(c, a) in between the link and unlink, but then if they had done that before the link() we couldn't tell the difference). That sounds like less of a problem than "mv" clobbering a file when we explicitly requested it not to. However I suppose link() has restrictions that rename() doesn't have (like the /proc/sys/fs/protected_hardlinks in Linux 3.6+) so it couldn't be used for at least that reason. -- Stephane