cmArchiveWrite: do not store sparse files when using standard tar formats

Sparse files in tars are a GNU extension that libarchive will use if it
detects holes in the input file, even when using the standard pax/paxr
formats. Not all tar implementations can handle sparse files; in particular,
the internal implementation dpkg uses to extract packages can't. To
maximize archive portability, turn this feature off by clearing the
sparseness information from archive entries.
This commit is contained in:
Roman Donchenko 2015-07-06 17:54:19 +03:00 committed by Brad King
parent 7e86f567ac
commit edae40239e
2 changed files with 11 additions and 1 deletions

View File

@ -84,7 +84,8 @@ cmArchiveWrite::cmArchiveWrite(
Stream(os), Stream(os),
Archive(archive_write_new()), Archive(archive_write_new()),
Disk(archive_read_disk_new()), Disk(archive_read_disk_new()),
Verbose(false) Verbose(false),
Format(format)
{ {
switch (c) switch (c)
{ {
@ -282,6 +283,14 @@ bool cmArchiveWrite::AddFile(const char* file,
archive_entry_acl_clear(e); archive_entry_acl_clear(e);
archive_entry_xattr_clear(e); archive_entry_xattr_clear(e);
archive_entry_set_fflags(e, 0, 0); archive_entry_set_fflags(e, 0, 0);
if (this->Format == "pax" || this->Format == "paxr")
{
// Sparse files are a GNU tar extension.
// Do not use them in standard tar files.
archive_entry_sparse_clear(e);
}
if(archive_write_header(this->Archive, e) != ARCHIVE_OK) if(archive_write_header(this->Archive, e) != ARCHIVE_OK)
{ {
this->Error = "archive_write_header: "; this->Error = "archive_write_header: ";

View File

@ -84,6 +84,7 @@ private:
struct archive* Archive; struct archive* Archive;
struct archive* Disk; struct archive* Disk;
bool Verbose; bool Verbose;
std::string Format;
std::string Error; std::string Error;
std::string MTime; std::string MTime;
}; };