diff options
author | Pádraig Brady <P@draigBrady.com> | 2023-04-03 18:06:22 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2023-04-04 11:39:33 +0100 |
commit | 94496522f25f19673acb759409d4cdcc6038daee (patch) | |
tree | 27f0a96e79e806faaa99bb2b90f5723db9153f82 /lib/backupfile.c | |
parent | 6b4ef50c64e606f11afcd9e8a063f05c835bb4a6 (diff) | |
download | gnulib-94496522f25f19673acb759409d4cdcc6038daee.tar.gz |
backupfile: fix bug when renaming from subdirectory
* lib/backupfile.c (backup_internal): Ensure we use the
appropriate offset if operating on a subdirectory,
i.e., on an updated sdir.
Fixes https://bugs.gnu.org/62607
Diffstat (limited to 'lib/backupfile.c')
-rw-r--r-- | lib/backupfile.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/backupfile.c b/lib/backupfile.c index 9cca271343..5bcf924414 100644 --- a/lib/backupfile.c +++ b/lib/backupfile.c @@ -331,7 +331,7 @@ backupfile_internal (int dir_fd, char const *file, return s; DIR *dirp = NULL; - int sdir = dir_fd; + int sdir = -1; idx_t base_max = 0; while (true) { @@ -370,9 +370,10 @@ backupfile_internal (int dir_fd, char const *file, if (! rename) break; - idx_t offset = backup_type == simple_backups ? 0 : base_offset; + dir_fd = sdir < 0 ? dir_fd : sdir; + idx_t offset = sdir < 0 ? 0 : base_offset; unsigned flags = backup_type == simple_backups ? 0 : RENAME_NOREPLACE; - if (renameatu (sdir, file + offset, sdir, s + offset, flags) == 0) + if (renameatu (dir_fd, file + offset, dir_fd, s + offset, flags) == 0) break; int e = errno; if (! (e == EEXIST && extended)) |