]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add ARCHIVE_READDISK_NO_SPARSE to suppress reading sparse file info
authorJonas Witschel <diabonas@archlinux.org>
Sun, 14 Nov 2021 17:56:49 +0000 (18:56 +0100)
committerJonas Witschel <diabonas@archlinux.org>
Sun, 14 Nov 2021 17:56:49 +0000 (18:56 +0100)
Sparse file information depends on the file system and can therefore be a
source of unreproducibility for the generated archives, e.g. if the same
content is compressed on a file system with and without sparse file support.
Add an option to suppress reading this information from disk entirely.

libarchive/archive.h
libarchive/archive_read_disk.3
libarchive/archive_read_disk_entry_from_file.c
libarchive/archive_read_disk_windows.c

index fbc96bfe76ddd6d2e8a67f4fa1860313b2a050a5..9fcb63024fa19628270ade87e46064e01490d4f9 100644 (file)
@@ -1024,6 +1024,8 @@ __LA_DECL int  archive_read_disk_set_atime_restored(struct archive *);
 #define        ARCHIVE_READDISK_NO_ACL                 (0x0020)
 /* Default: File flags are read from disk. */
 #define        ARCHIVE_READDISK_NO_FFLAGS              (0x0040)
+/* Default: Sparse file information is read from disk. */
+#define        ARCHIVE_READDISK_NO_SPARSE              (0x0080)
 
 __LA_DECL int  archive_read_disk_set_behavior(struct archive *,
                    int flags);
index 82d6a5c8562cda26e58a92aad741047b4138243c..a7e376fffa540d98fbe1d577aa606119fc258721 100644 (file)
@@ -137,6 +137,9 @@ for more information on extended file attributes.
 .It Cm ARCHIVE_READDISK_RESTORE_ATIME
 Restore access time of traversed files.
 By default, access time of traversed files is not restored.
+.It Cm ARCHIVE_READDISK_NO_SPARSE
+Do not read sparse file information.
+By default, sparse file information is read from disk.
 .El
 .It Xo
 .Fn archive_read_disk_set_symlink_logical ,
index 9c9cf38ee9f17e5f5b11e54b559da5e32fec1803..ab0270bc28501c3d0b2c51e79786e65e03a7ac26 100644 (file)
@@ -303,9 +303,11 @@ archive_read_disk_entry_from_file(struct archive *_a,
                if (r1 < r)
                        r = r1;
        }
-       r1 = setup_sparse(a, entry, &fd);
-       if (r1 < r)
-               r = r1;
+       if ((a->flags & ARCHIVE_READDISK_NO_SPARSE) == 0) {
+               r1 = setup_sparse(a, entry, &fd);
+               if (r1 < r)
+                       r = r1;
+       }
 
        /* If we opened the file earlier in this function, close it. */
        if (initial_fd != fd)
index 877bc449a765c32df472af0104c5e6e365a0882f..a2587c527332b0fa3b9cbeaeb11e7ef819e3cd89 100644 (file)
@@ -1090,9 +1090,11 @@ next_entry(struct archive_read_disk *a, struct tree *t,
                }
 
                /* Find sparse data from the disk. */
-               if (archive_entry_hardlink(entry) == NULL &&
-                   (st->dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0)
-                       r = setup_sparse_from_disk(a, entry, t->entry_fh);
+               if ((a->flags & ARCHIVE_READDISK_NO_SPARSE) == 0) {
+                       if (archive_entry_hardlink(entry) == NULL &&
+                           (st->dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0)
+                               r = setup_sparse_from_disk(a, entry, t->entry_fh);
+               }
        }
        return (r);
 }
@@ -2371,9 +2373,11 @@ archive_read_disk_entry_from_file(struct archive *_a,
                return (ARCHIVE_OK);
        }
 
-       r = setup_sparse_from_disk(a, entry, h);
-       if (fd < 0)
-               CloseHandle(h);
+       if ((a->flags & ARCHIVE_READDISK_NO_SPARSE) == 0) {
+               r = setup_sparse_from_disk(a, entry, h);
+               if (fd < 0)
+                       CloseHandle(h);
+       }
 
        return (r);
 }