Upstream patch on top of coreutils-9.1; remove with >9.1. Fixes: https://bugs.gnu.org/55029 Two commits: * https://git.sv.gnu.org/cgit/coreutils.git/commit/?id=e087525091b commit e087525091b8f0a15eb2354f71032597d5271599 Author: Paul Eggert Date: Wed Apr 20 19:44:56 2022 -0700 mv: test Bug#55029 * tests/mv/backup-dir.sh: New test for Bug#55029, reported by Steve Ward. * https://git.sv.gnu.org/cgit/gnulib.git/commit/?id=7347caeb9d90 commit 7347caeb9d902d3fca2c11f69a55a3e578d93bfe Author: Paul Eggert Date: Wed Apr 20 19:34:57 2022 -0700 backupfile: fix bug when renaming simple backups * lib/backupfile.c (backupfile_internal): Fix bug when RENAME and when doing simple backups. Problem reported by Steve Ward in: https://bugs.gnu.org/55029 --- NEWS | 8 ++++++++ lib/backupfile.c | 7 +++---- tests/mv/backup-dir.sh | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) Index: lib/backupfile.c =================================================================== --- lib/backupfile.c.orig +++ lib/backupfile.c @@ -332,7 +332,7 @@ backupfile_internal (int dir_fd, char co return s; DIR *dirp = NULL; - int sdir = AT_FDCWD; + int sdir = dir_fd; idx_t base_max = 0; while (true) { @@ -371,10 +371,9 @@ backupfile_internal (int dir_fd, char co if (! rename) break; - int olddirfd = sdir < 0 ? dir_fd : sdir; - idx_t offset = sdir < 0 ? 0 : base_offset; + idx_t offset = backup_type == simple_backups ? 0 : base_offset; unsigned flags = backup_type == simple_backups ? 0 : RENAME_NOREPLACE; - if (renameatu (olddirfd, file + offset, sdir, s + offset, flags) == 0) + if (renameatu (sdir, file + offset, sdir, s + offset, flags) == 0) break; int e = errno; if (! (e == EEXIST && extended)) Index: tests/mv/backup-dir.sh =================================================================== --- tests/mv/backup-dir.sh.orig +++ tests/mv/backup-dir.sh @@ -36,4 +36,10 @@ mkdir C D E || framework_failure_ mv -T --backup=numbered C E/ || fail=1 mv -T --backup=numbered D E/ || fail=1 +# Bug#55029 +mkdir F && echo 1 >1 && echo 2 >2 && cp 1 F/X && cp 2 X || framework_failure_ +mv --backup=simple X F/ || fail=1 +compare 1 F/X~ || fail=1 +compare 2 F/X || fail=1 + Exit $fail Index: NEWS =================================================================== --- NEWS.orig +++ NEWS @@ -1,5 +1,13 @@ GNU coreutils NEWS -*- outline -*- +* Downstream changes on top of release 9.1 + +** Bug fixes + + 'mv --backup=simple f d/' no longer mistakenly backs up d/f to f~. + [bug introduced in coreutils-9.1] + + * Noteworthy changes in release 9.1 (2022-04-15) [stable] ** Bug fixes