bug-coreutils
[Top][All Lists]
Advanced

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

bug#69532: mv's new -x option should be made orthogonal to -t/-T/default


From: Petr Malat
Subject: bug#69532: mv's new -x option should be made orthogonal to -t/-T/default
Date: Tue, 5 Mar 2024 00:37:44 +0100

Hi Paul,
On Sun, Mar 03, 2024 at 04:44:52PM -0800, Paul Eggert wrote:
> Although I like the idea of exposing file swaps to the user, the first cut
> of 'mv -x' has significant problems.
> 
> I expect 'mv -x A B' to act like 'mv A B' except the destination must exist
> and is renamed back to A. However, this is not true for 'mv -x A B' when B
> is a directory; it renames B to A rather than renaming B/A to A as I expect.
> That is, 'mv -x' acts as if -T (--no-target-directory) is also specified.
> There is no way to get mv's traditional behavior, or to get mv -t behavior.

Why do you expect this? If the description in the help output was not
clear enough we can improve it by mentioning it implies -T.

> To fix this, 'mv -x' should respect the usual mv behavior with respect to
> directories. For example, when D is a directory 'mv -x A B C D' should act
> like 'mv A B C D' except that D's old entries should be renamed back to A B
> and C. And the -t and -T options should work with -x the same way they work
> when -x is not specified.

I do not think this is a good idea, because that operation is not
atomic. Probably, the user wants to prepare a temporary directory
instead and then atomically swap it with the directory in use.

The main motivation for this option is not to preserve old files, 
but to be able to atomically replace one file with another. If one
needs to preserve replaced files, he can use the backup option.

Supporting swap for more than 2 files also brings a problem, when
the operation fails as then one doesn't know what has been swapped
and what not. With plain mv one knows the file was moved if the
original location is unlinked.
BR,
  Petr





reply via email to

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