archrelease: copy trunk to extra-x86_64
[arch-packages.git] / coreutils / repos / core-x86_64 / gnulib-backupfile-62607.patch
blob53f281269d4460d34c1986969df73f083734b053
1 From 418aa564ebff70c1d118a5d3307a6d0b147ff7a2 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
3 Date: Mon, 3 Apr 2023 18:06:22 +0100
4 Subject: [PATCH] backupfile: fix bug when renaming from subdirectory
6 * lib/backupfile.c (backup_internal): Ensure we use the
7 appropriate offset if operating on a subdirectory,
8 i.e., on an updated sdir.
9 Fixes https://bugs.gnu.org/62607
10 ---
11 ChangeLog | 8 ++++++++
12 lib/backupfile.c | 7 ++++---
13 2 files changed, 12 insertions(+), 3 deletions(-)
15 diff --git a/lib/backupfile.c b/lib/backupfile.c
16 index 9cca271343..5bcf924414 100644
17 --- a/lib/backupfile.c
18 +++ b/lib/backupfile.c
19 @@ -331,7 +331,7 @@ backupfile_internal (int dir_fd, char const *file,
20 return s;
22 DIR *dirp = NULL;
23 - int sdir = dir_fd;
24 + int sdir = -1;
25 idx_t base_max = 0;
26 while (true)
28 @@ -370,9 +370,10 @@ backupfile_internal (int dir_fd, char const *file,
29 if (! rename)
30 break;
32 - idx_t offset = backup_type == simple_backups ? 0 : base_offset;
33 + dir_fd = sdir < 0 ? dir_fd : sdir;
34 + idx_t offset = sdir < 0 ? 0 : base_offset;
35 unsigned flags = backup_type == simple_backups ? 0 : RENAME_NOREPLACE;
36 - if (renameatu (sdir, file + offset, sdir, s + offset, flags) == 0)
37 + if (renameatu (dir_fd, file + offset, dir_fd, s + offset, flags) == 0)
38 break;
39 int e = errno;
40 if (! (e == EEXIST && extended))
41 --
42 2.26.2