Comment by amstan
18 hours ago
Missing (probably because of the date of the article): `mv --exchange` aka renameat2+RENAME_EXCHANGE. It atomically swaps 2 file paths.
18 hours ago
Missing (probably because of the date of the article): `mv --exchange` aka renameat2+RENAME_EXCHANGE. It atomically swaps 2 file paths.
I tried using this a while back and found it was not widely available. You need coreutils version 9.1 or later for this, many distros do not ship this.
I made https://github.com/rubenvannieuwpoort/atomic-exchange for my usecase.
Title says Unix, renameat2 is Linux-only.
>Title says Unix,
You're misinterpreting the title. The author didn't intend "Unix" to literally mean only the official AT&T/TheOpenGroup UNIX® System to the exclusion of Linux.
The first sentence of "UNIX-like" makes that clear : >This is a catalog of things UNIX-like/POSIX-compliant operating systems can do atomically,
Further down, he then mentions some Linux specifics : >fcntl(fd, F_GETLK, &lock), fcntl(fd, F_SETLK, &lock), and fcntl(fd, F_SETLKW, &lock) . [...] There is a “mandatory locking” mode but Linux’s implementation is unreliable as it’s subject to a race condition.
Bit rot alert: Linux doesn't even have mandatory file locks these days.
Linux-specific open file description locks could be brought up in a modern version of TFA though.
They aren’t misinterpreting the title, the title is incorrect.
1 reply →
But I also don't think the auther meant Things you can do in Linux but not Unix
5 replies →
Except POSIX doesn't specify some of them as happening atomically.
Many people write UNIX/POSIX without ever reading what it says.
Sounds like the key term then is probably this:
> POSIX-compliant
Which, FWIW, doesn't mean Linux. AFAIK there is no Linux distro that's fully compliant, even before you worry about the specifics of whether it's certified as compliant.
5 replies →