summaryrefslogtreecommitdiff
path: root/tar
diff options
context:
space:
mode:
authorMartin Matuška <martin@matuska.org>2021-11-21 11:32:19 +0100
committerGitHub <noreply@github.com>2021-11-21 11:32:19 +0100
commit4f598ce28aa370e945103eb9a17f03c7c820c1e8 (patch)
treeb236dccabee9d88383dc934e7e719105d84095fe /tar
parent6795d0255584c863d7f5ceb3038e53c9ad3f135a (diff)
parent1833a6c4d40a57f5782ac2f96b375923c51024ea (diff)
downloadlibarchive-4f598ce28aa370e945103eb9a17f03c7c820c1e8.tar.gz
Merge pull request #1614 from diabonas/add-no-read-sparse
Add ARCHIVE_READDISK_NO_SPARSE/--no-read-sparse to improve reproducibility of generated archives
Diffstat (limited to 'tar')
-rw-r--r--tar/bsdtar.111
-rw-r--r--tar/bsdtar.c8
-rw-r--r--tar/bsdtar.h4
-rw-r--r--tar/cmdline.c2
4 files changed, 25 insertions, 0 deletions
diff --git a/tar/bsdtar.1 b/tar/bsdtar.1
index 86a06bbd..b1504700 100644
--- a/tar/bsdtar.1
+++ b/tar/bsdtar.1
@@ -470,6 +470,11 @@ This is the reverse of
and the default behavior if
.Nm
is run as non-root in x mode.
+.It Fl Fl no-read-sparse
+(c, r, u modes only)
+Do not read sparse file information from disk.
+This is the reverse of
+.Fl Fl read-sparse .
.It Fl Fl no-safe-writes
(x mode only)
Do not create temporary files and use
@@ -730,6 +735,12 @@ By default, the archive is always read to the very end, since
there can be multiple entries with the same name and, by convention,
later entries overwrite earlier entries.
This option is provided as a performance optimization.
+.It Fl Fl read-sparse
+(c, r, u modes only)
+Read sparse file information from disk.
+This is the reverse of
+.Fl Fl no-read-sparse
+and the default behavior.
.It Fl S
(x mode only)
Extract files as sparse files.
diff --git a/tar/bsdtar.c b/tar/bsdtar.c
index af41be5e..df0930ae 100644
--- a/tar/bsdtar.c
+++ b/tar/bsdtar.c
@@ -542,6 +542,10 @@ main(int argc, char **argv)
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_MAC_METADATA;
bsdtar->flags |= OPTFLAG_NO_MAC_METADATA;
break;
+ case OPTION_NO_READ_SPARSE:
+ bsdtar->readdisk_flags |= ARCHIVE_READDISK_NO_SPARSE;
+ bsdtar->flags |= OPTFLAG_NO_READ_SPARSE;
+ break;
case OPTION_NO_SAFE_WRITES:
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_SAFE_WRITES;
break;
@@ -649,6 +653,10 @@ main(int argc, char **argv)
case 'r': /* SUSv2 */
set_mode(bsdtar, opt);
break;
+ case OPTION_READ_SPARSE:
+ bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_NO_SPARSE;
+ bsdtar->flags |= OPTFLAG_READ_SPARSE;
+ break;
case 'S': /* NetBSD pax-as-tar */
bsdtar->extract_flags |= ARCHIVE_EXTRACT_SPARSE;
break;
diff --git a/tar/bsdtar.h b/tar/bsdtar.h
index 89aa3aa9..8f9f79ab 100644
--- a/tar/bsdtar.h
+++ b/tar/bsdtar.h
@@ -129,6 +129,8 @@ struct bsdtar {
#define OPTFLAG_FFLAGS (0x00100000) /* --fflags */
#define OPTFLAG_NO_MAC_METADATA (0x00200000) /* --no-mac-metadata */
#define OPTFLAG_MAC_METADATA (0x00400000) /* --mac-metadata */
+#define OPTFLAG_NO_READ_SPARSE (0x00800000) /* --no-read-sparse */
+#define OPTFLAG_READ_SPARSE (0x01000000) /* --read-sparse */
/* Fake short equivalents for long options that otherwise lack them. */
enum {
@@ -164,6 +166,7 @@ enum {
OPTION_NO_ACLS,
OPTION_NO_FFLAGS,
OPTION_NO_MAC_METADATA,
+ OPTION_NO_READ_SPARSE,
OPTION_NO_SAFE_WRITES,
OPTION_NO_SAME_OWNER,
OPTION_NO_SAME_PERMISSIONS,
@@ -178,6 +181,7 @@ enum {
OPTION_OPTIONS,
OPTION_PASSPHRASE,
OPTION_POSIX,
+ OPTION_READ_SPARSE,
OPTION_SAFE_WRITES,
OPTION_SAME_OWNER,
OPTION_STRIP_COMPONENTS,
diff --git a/tar/cmdline.c b/tar/cmdline.c
index b80937ff..d49e5b0d 100644
--- a/tar/cmdline.c
+++ b/tar/cmdline.c
@@ -122,6 +122,7 @@ static const struct bsdtar_option {
{ "no-acls", 0, OPTION_NO_ACLS },
{ "no-fflags", 0, OPTION_NO_FFLAGS },
{ "no-mac-metadata", 0, OPTION_NO_MAC_METADATA },
+ { "no-read-sparse", 0, OPTION_NO_READ_SPARSE },
{ "no-recursion", 0, 'n' },
{ "no-safe-writes", 0, OPTION_NO_SAFE_WRITES },
{ "no-same-owner", 0, OPTION_NO_SAME_OWNER },
@@ -145,6 +146,7 @@ static const struct bsdtar_option {
{ "posix", 0, OPTION_POSIX },
{ "preserve-permissions", 0, 'p' },
{ "read-full-blocks", 0, 'B' },
+ { "read-sparse", 0, OPTION_READ_SPARSE },
{ "safe-writes", 0, OPTION_SAFE_WRITES },
{ "same-owner", 0, OPTION_SAME_OWNER },
{ "same-permissions", 0, 'p' },