On Wednesday 12 of November 2014 16:01:52 Hendrik Grewe wrote:
> If one tries to append a file to an existing .tar file through
> 
>   tar --append --file defective.tar fileToAdd.xxx
> 
> tar may return exit code 0 and terminate without error though the
> fileToAdd.xxx is not added to the .tar file. However the tarfile has
> been changed in some kinde since md5sums of defective.tar befor the
> non working call and after the call differ.
> [...]
> The defective tar file (generated by pg_basebackup) may be found here:
> 
> https://depot.tu-dortmund.de/get/8aq4g
> 
> If you need any further information feel free to contact me.

Thanks for the report.  The archive is not aligned to record_size (which
is not an issue, just the issue trigger).  You may test the first attached
patch.

The second patch should just avoid unnecessary busy reading of seek-able
archives.

Pavel
>From 05dd32756c98df54c1a5169f8039dcafcfb45eac Mon Sep 17 00:00:00 2001
From: Pavel Raiskup <[email protected]>
Date: Mon, 17 Nov 2014 13:13:15 +0100
Subject: [PATCH 1/2] Fix unaligned archive corruption with --append

If a archive size is not a factor of --block-size, do not
backspace the archive of whole record_size.

* src/buffer.c (backspace_output): Seek back only to beginning of
the current record.
---
 src/buffer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/buffer.c b/src/buffer.c
index a7d8971..5dd48f7 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1031,7 +1031,13 @@ backspace_output (void)
 
     /* Seek back to the beginning of this record and start writing there.  */
 
-    position -= record_size;
+    off_t bs = position % record_size;
+
+    if (!bs)
+      bs = record_size;
+
+    position -= bs;
+
     if (position < 0)
       position = 0;
     if (rmtlseek (archive, position, SEEK_SET) != position)
-- 
1.9.3

>From a3d4a705f5b2adc9ec5311085faaa4c41d5a3df7 Mon Sep 17 00:00:00 2001
From: Pavel Raiskup <[email protected]>
Date: Mon, 17 Nov 2014 13:26:01 +0100
Subject: [PATCH 2/2] Allow seeking in archive with --append

* src/buffer.c (_open_archive): Call guess_seekable_archive.
---
 src/buffer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/buffer.c b/src/buffer.c
index 5dd48f7..80432c1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -800,6 +800,7 @@ _open_archive (enum access_mode wanted_access)
         archive = rmtopen (archive_name_array[0],
                            O_RDWR | O_CREAT | O_BINARY,
                            MODE_RW, rsh_command_option);
+        guess_seekable_archive ();
 
         switch (check_compressed_archive (NULL))
           {
-- 
1.9.3

Reply via email to