bug#29961: [PATCH] mv -n: do not overwrite the destination
From:
Paul Eggert
Subject:
bug#29961: [PATCH] mv -n: do not overwrite the destination
Date:
Fri, 5 Jan 2018 14:59:06 -0800
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0
On 01/05/2018 08:19 AM, Kamil Dudka wrote:
I am only fixing the case where the destination file is created after the
lstat() call. In that case, the only result is ENOENT, which is harmless.
Ah, you're right. Sorry, I misread your patch. It should work.
On Friday, January 5, 2018 4:29:55 PM CET PƔdraig Brady wrote:
Paul's also avoids a stat() in the common case
where the initial renameat2() succeeds.
At the cost of _not_ avoiding the renameat2() call in the most common case.
I expect that the most common case is 'mv A B' where B does not already
exist. This is the case that avoids the stat of B.
Come to think of it, we don't need to stat A either, when the initial
renameat2 succeeds. Attached is a revised proposed patchset to do that.
The first is the same as before; the second causes 'mv A B' to issue
just a renameat2 syscall (with no calls to stat) in the common case
where A exists and B does not.
I will go with my conservative (or even the
documentation-only) patch for RHEL-7, which was the trigger of this effort,
because Paul's patch comes with changes of behavior observable beyond the