GNU bug report logs - #55029
Simple backup swaps source and destination files

Previous Next

Package: coreutils;

Reported by: Steve Ward <planet36 <at> gmail.com>

Date: Tue, 19 Apr 2022 23:06:01 UTC

Severity: normal

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

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 55029 in the body.
You can then email your comments to 55029 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#55029; Package coreutils. (Tue, 19 Apr 2022 23:06:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Steve Ward <planet36 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 19 Apr 2022 23:06:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Steve Ward <planet36 <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: Simple backup swaps source and destination files
Date: Tue, 19 Apr 2022 19:05:09 -0400
When doing mv or cp with --backup=simple, if an existing file in
DIRECTORY has the same name as SOURCE, the files appear to be swapped
instead of an in-place backup of the original file in DIRECTORY being
made.
It doesn't happen with --backup=numbered.  SIMPLE_BACKUP_SUFFIX is not set.

Steps to reproduce:

$ mkdir tmp
$ echo "first file" > tmp/a
$ echo "second file" > a
$ command mv -v --backup=simple a tmp/
renamed 'a' -> 'tmp/a' (backup: 'tmp/a~')

$ cat tmp/a~
cat: tmp/a~: No such file or directory

$ cat a~
first file

Version info:

$ mv --version | head -n 1
mv (GNU coreutils) 9.1

$ uname -srm
Linux 5.17.3-arch1-1 x86_64

$ ldd --version | head -n 1
ldd (GNU libc) 2.35

The filesystem type is ext4.




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 21 Apr 2022 02:54:02 GMT) Full text and rfc822 format available.

Notification sent to Steve Ward <planet36 <at> gmail.com>:
bug acknowledged by developer. (Thu, 21 Apr 2022 02:54:02 GMT) Full text and rfc822 format available.

Message #10 received at 55029-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Steve Ward <planet36 <at> gmail.com>
Cc: Gnulib bugs <bug-gnulib <at> gnu.org>, 55029-done <at> debbugs.gnu.org
Subject: Re: bug#55029: Simple backup swaps source and destination files
Date: Wed, 20 Apr 2022 19:53:06 -0700
[Message part 1 (text/plain, inline)]
On 4/19/22 16:05, Steve Ward wrote:
> When doing mv or cp with --backup=simple, if an existing file in
> DIRECTORY has the same name as SOURCE, the files appear to be swapped
> instead of an in-place backup of the original file in DIRECTORY being
> made.

Thanks for the bug report. That's new to coreutils 9.1, and is a big 
enough fail that it suggests we'll need a 9.2 sooner rather than later. 
I introduced the bug when fixing an earlier bug (sorry).

I installed the attached Gnulib patch, which should fix the bug in 
Coreutils, with the attached two Coreutils patches to update to the 
latest Gnulib, and to add a test case for the bug.
[0001-backupfile-fix-bug-when-renaming-simple-backups.patch (text/x-patch, attachment)]
[0001-build-update-gnulib-submodule-to-latest.patch (text/x-patch, attachment)]
[0002-mv-test-Bug-55029.patch (text/x-patch, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#55029; Package coreutils. (Sat, 23 Apr 2022 14:44:01 GMT) Full text and rfc822 format available.

Message #13 received at 55029 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: 55029 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu, planet36 <at> gmail.com
Subject: Re: bug#55029: Simple backup swaps source and destination files
Date: Sat, 23 Apr 2022 15:42:50 +0100
On 21/04/2022 03:53, Paul Eggert wrote:
> On 4/19/22 16:05, Steve Ward wrote:
>> When doing mv or cp with --backup=simple, if an existing file in
>> DIRECTORY has the same name as SOURCE, the files appear to be swapped
>> instead of an in-place backup of the original file in DIRECTORY being
>> made.
> 
> Thanks for the bug report. That's new to coreutils 9.1, and is a big
> enough fail that it suggests we'll need a 9.2 sooner rather than later.
> I introduced the bug when fixing an earlier bug (sorry).
> 
> I installed the attached Gnulib patch, which should fix the bug in
> Coreutils, with the attached two Coreutils patches to update to the
> latest Gnulib, and to add a test case for the bug.

Thanks for the fix.

For the record, another failure mode is with different file systems:
  $ echo 1 > /tmp/a
  $ echo 2 > a
  $ echo 3 > a~
  $ src/mv -v --backup=simple a /tmp
  src/mv: cannot backup '/tmp/a': Invalid cross-device link
In this case the failure is not silent, and no changes are made.
This is a bit better, in that there is no possibility of silent data loss.

For the same file system case you might lose data in a setup like:
  $ cd workdir
  $ gen_data1 > data
  $ mv --backup=simple data1/
  $ gen_data2 > data
  $ mv --backup=simple data2/
In which case you'd lose the data~ backups in each of the data?/ dirs.

Another case which might be more problematic is with install(1).
  $ install --backup=simple blah /usr/local/dir
In which case we'd lose the blah~ backup upon removal of the build dir.

Note --backup without a specific type will default to simple
or numbered as appropriate, but this does _not_ have the
issue when defaulting to simple.

I've applied the fix to Fedora rawhide which had already moved to 9.1.
I've reported git issue at https://bugs.archlinux.org/task/74544

This should induce a coreutils 9.2 sooner,
but I don't think we need an immediate release just yet.

thanks,
Pádraig




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 22 May 2022 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 311 days ago.

Previous Next


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