coreutils
[Top][All Lists]
Advanced

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

Re: Atomic rename failure detection


From: Collin Funk
Subject: Re: Atomic rename failure detection
Date: Sat, 25 Oct 2025 00:34:55 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

"Philip Rowlands" <phr+coreutils@dimebar.com> writes:

> Would it be worthwhile having an option e.g. --no-clobber=fail to
> modify the exit status when mv didn't perform the rename?
>
> I haven't thought too hard about the semantics of moving a bunch of
> files to a target directory, but we  presumably have to deal with this
> today for -i / -b.
>
> The use case is simply race-free renames. Imagine all the locking
> schemes you could implement with mv(1)!

Does flock(1) not work for your use case [1]? That is what I would use
if I needed locks.

Here is a trivial example. In shell 1:

   $ flock lock -c 'sleep 10'

Immediately after in shell 2:

   $ time flock lock -c 'echo hello'
   hello

   real 0m9.704s
   user 0m0.000s
   sys  0m0.003s

Collin

[1] https://man7.org/linux/man-pages/man1/flock.1.html



reply via email to

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