GNU bug report logs - #29961
[PATCH] mv: document the missing atomicity of 'mv -n'

Previous Next

Package: coreutils;

Reported by: Kamil Dudka <kdudka <at> redhat.com>

Date: Wed, 3 Jan 2018 15:03:02 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Kamil Dudka <kdudka <at> redhat.com>, Pádraig Brady <P <at> draigBrady.com>
Cc: 29961 <at> debbugs.gnu.org
Subject: bug#29961: [PATCH] mv -n: do not overwrite the destination
Date: Thu, 4 Jan 2018 01:48:56 -0800
[Message part 1 (text/plain, inline)]
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?
[0001-mv-improve-n-atomicity.patch (text/x-patch, attachment)]

This bug report was last modified 7 years and 139 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.