]> Savannah Git Hosting - gnulib.git/commitdiff
backupfile: fix bug when renaming simple backups
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 21 Apr 2022 02:34:57 +0000 (19:34 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 21 Apr 2022 02:35:25 +0000 (19:35 -0700)
* 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

ChangeLog
lib/backupfile.c

index 4b39a6a4437840ec8269fe0e84afeef093fa8eac..cd16bbe0cde577d1f407899d498c3e49dc123253 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2022-04-20  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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
+
        gettime-res: more-robust sampling
        * lib/gettime-res.c (gettime_res): If adjacent timestamps are
        identical search for a differing timestamp.  Also, stop collecting
index 1e9290a1872bcaa269a31225e2a99ce46c06593a..d9f465a3e0eaa8bdd0764247dbf285a5b14455c8 100644 (file)
@@ -332,7 +332,7 @@ backupfile_internal (int dir_fd, char const *file,
     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 const *file,
       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))