dd0dbfb
From d437ecf75de2d6fdeb2aed6f45c4b3b16373389b Mon Sep 17 00:00:00 2001
dd0dbfb
From: Sergey Poznyakoff <gray@gnu.org>
dd0dbfb
Date: Fri, 11 Aug 2023 21:35:30 +0300
dd0dbfb
Subject: [PATCH] Revert "Fix savannah bug #63567"
dd0dbfb
dd0dbfb
Commit e89c7a45eb broke deletion from archives. The reported number
dd0dbfb
of bytes read is rounded to the nearest record anyway, revert the
dd0dbfb
commit and document the fact.
dd0dbfb
dd0dbfb
Reported by Ed Santiago. See
dd0dbfb
https://bugzilla.redhat.com/show_bug.cgi?id=2230127
dd0dbfb
dd0dbfb
* doc/tar.texi: Document the fact that --totals rounds up the
dd0dbfb
number of bytes reads to the nearest record.
dd0dbfb
* src/buffer.c: Revert changes.
dd0dbfb
* tests/delete06.at: Fix expected status code and stderr.
dd0dbfb
---
dd0dbfb
 doc/tar.texi      | 5 +++++
dd0dbfb
 src/buffer.c      | 3 +--
dd0dbfb
 tests/delete06.at | 7 +++++--
dd0dbfb
 3 files changed, 11 insertions(+), 4 deletions(-)
dd0dbfb
dd0dbfb
diff --git a/doc/tar.texi b/doc/tar.texi
dd0dbfb
index d43b39e4..ee631137 100644
dd0dbfb
--- a/doc/tar.texi
dd0dbfb
+++ b/doc/tar.texi
dd0dbfb
@@ -4215,6 +4215,11 @@ Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
dd0dbfb
 @end group
dd0dbfb
 @end smallexample
dd0dbfb
 
dd0dbfb
+Notice, that since @command{tar} operates on @dfn{records}, the number
dd0dbfb
+of bytes reported can be rounded up to the nearest full record.  This
dd0dbfb
+can happen, in particular, when the last record in the archive is
dd0dbfb
+partial.  @xref{Blocking}.
dd0dbfb
+
dd0dbfb
 Finally, when deleting from an archive, the @option{--totals} option
dd0dbfb
 displays both numbers plus number of bytes removed from the archive:
dd0dbfb
 
dd0dbfb
diff --git a/src/buffer.c b/src/buffer.c
dd0dbfb
index 12a0579f..8a575f9a 100644
dd0dbfb
--- a/src/buffer.c
dd0dbfb
+++ b/src/buffer.c
dd0dbfb
@@ -987,8 +987,7 @@ short_read (size_t status)
dd0dbfb
     }
dd0dbfb
 
dd0dbfb
   record_end = record_start + (record_size - left) / BLOCKSIZE;
dd0dbfb
-  if (left == 0)
dd0dbfb
-    records_read++;
dd0dbfb
+  records_read++;
dd0dbfb
 }
dd0dbfb
 
dd0dbfb
 /*  Flush the current buffer to/from the archive.  */
dd0dbfb
diff --git a/tests/delete06.at b/tests/delete06.at
dd0dbfb
index 9668a28c..c84ba20e 100644
dd0dbfb
--- a/tests/delete06.at
dd0dbfb
+++ b/tests/delete06.at
dd0dbfb
@@ -36,7 +36,10 @@ esac
dd0dbfb
 dd if=archive.tar of=trunc.tar bs=$size count=1 2>/dev/null
dd0dbfb
 tar --delete 'b/' -f trunc.tar
dd0dbfb
 ],
dd0dbfb
-[0],
dd0dbfb
-[],[],[],[],[gnu, pax])
dd0dbfb
+[2],
dd0dbfb
+[],
dd0dbfb
+[tar: lseek: trunc.tar: Value too large for defined data type
dd0dbfb
+tar: Exiting with failure status due to previous errors
dd0dbfb
+],[],[],[gnu, pax])
dd0dbfb
 
dd0dbfb
 AT_CLEANUP
dd0dbfb
-- 
dd0dbfb
2.41.0
dd0dbfb