Browse Source

Fix --delete bug with short reads

* gnulib.modules: Add idx.
* src/common.h: Include idx.h.
* src/delete.c (move_archive): Don’t botch short reads.
Paul Eggert 2 years ago
parent
commit
f8e14746d2
3 changed files with 10 additions and 2 deletions
  1. 1 0
      gnulib.modules
  2. 1 0
      src/common.h
  3. 8 2
      src/delete.c

+ 1 - 0
gnulib.modules

@@ -54,6 +54,7 @@ gettime
 gitlog-to-changelog
 hash
 human
+idx
 inttostr
 inttypes
 lchown

+ 1 - 0
src/common.h

@@ -53,6 +53,7 @@
 #include <backupfile.h>
 #include <exclude.h>
 #include <full-write.h>
+#include <idx.h>
 #include <modechange.h>
 #include <quote.h>
 #include <safe-read.h>

+ 8 - 2
src/delete.c

@@ -55,9 +55,15 @@ move_archive (off_t count)
   off_t position0 = rmtlseek (archive, 0, SEEK_CUR), position = 0;
   if (0 <= position0)
     {
-      off_t increment;
+      /* Pretend the starting position is at the first record
+	 boundary after POSITION0.  This is useful at EOF after
+	 a short read.  */
+      idx_t short_size = position0 % record_size;
+      idx_t start_offset = short_size ? record_size - short_size : 0;
+      off_t increment, move_start;
       if (INT_MULTIPLY_WRAPV (record_size, count, &increment)
-	  || INT_ADD_WRAPV (position0, increment, &position)
+	  || INT_ADD_WRAPV (position0, start_offset, &move_start)
+	  || INT_ADD_WRAPV (move_start, increment, &position)
 	  || position < 0)
 	{
 	  ERROR ((0, EOVERFLOW, "lseek: %s", archive_name_array[0]));