[Top][All Lists]

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

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: Thu, 4 Jan 2018 01:48:56 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

Kamil Dudka wrote:
-      if (rename (src_name, dst_name) == 0)
+      int flags = 0;
+      if (x->interactive == I_ALWAYS_NO)
+        /* do not replace DST_NAME if it was created since our last check */
+        flags = RENAME_NOREPLACE;

By then it's too late, as multiple decisions have been made on the basis of stat/lstat calls that are still subject to races. It's better to try the renameat2 with RENAME_NOREPLACE first thing, and fall back on the existing code only if renameat2 fails with errno != EEXIST.

Plus, there are some other problems when combining -u and -n.

How about the attached patch instead?

Attachment: 0001-mv-improve-n-atomicity.patch
Description: Text Data

reply via email to

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