Merge topic 'libarchive-wrapper'
fb41da4 Add Compress compress support to libarchive-wrapper 1a3ad5c Add XZ compress support to libarchive-wrapper b50c159 Add ZIP archive format and LZMA compress support to libarchive-wrapper 4663356 cmArchiveWrite: Fix signed/unsigned again
This commit is contained in:
commit
ab90916638
@ -47,7 +47,7 @@ struct cmArchiveWrite::Callback
|
|||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c):
|
cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t):
|
||||||
Stream(os),
|
Stream(os),
|
||||||
Archive(archive_write_new()),
|
Archive(archive_write_new()),
|
||||||
Disk(archive_read_disk_new()),
|
Disk(archive_read_disk_new()),
|
||||||
@ -63,6 +63,14 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c):
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CompressCompress:
|
||||||
|
if(archive_write_set_compression_compress(this->Archive) != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
this->Error = "archive_write_set_compression_compress: ";
|
||||||
|
this->Error += archive_error_string(this->Archive);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case CompressGZip:
|
case CompressGZip:
|
||||||
if(archive_write_set_compression_gzip(this->Archive) != ARCHIVE_OK)
|
if(archive_write_set_compression_gzip(this->Archive) != ARCHIVE_OK)
|
||||||
{
|
{
|
||||||
@ -79,14 +87,58 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c):
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CompressLZMA:
|
||||||
|
if(archive_write_set_compression_lzma(this->Archive) != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
this->Error = "archive_write_set_compression_lzma: ";
|
||||||
|
this->Error += archive_error_string(this->Archive);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CompressXZ:
|
||||||
|
if(archive_write_set_compression_xz(this->Archive) != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
this->Error = "archive_write_set_compression_xz: ";
|
||||||
|
this->Error += archive_error_string(this->Archive);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
};
|
};
|
||||||
archive_read_disk_set_standard_lookup(this->Disk);
|
#if !defined(_WIN32) || defined(__CYGWIN__)
|
||||||
|
if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
this->Error = "archive_read_disk_set_standard_lookup: ";
|
||||||
|
this->Error += archive_error_string(this->Archive);
|
||||||
|
return;;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
switch (t)
|
||||||
|
{
|
||||||
|
case TypeZIP:
|
||||||
|
if(archive_write_set_format_zip(this->Archive) != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
this->Error = "archive_write_set_format_zip: ";
|
||||||
|
this->Error += archive_error_string(this->Archive);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TypeTAR:
|
||||||
if(archive_write_set_format_pax_restricted(this->Archive) != ARCHIVE_OK)
|
if(archive_write_set_format_pax_restricted(this->Archive) != ARCHIVE_OK)
|
||||||
{
|
{
|
||||||
this->Error = "archive_write_set_format_pax_restricted: ";
|
this->Error = "archive_write_set_format_pax_restricted: ";
|
||||||
this->Error += archive_error_string(this->Archive);
|
this->Error += archive_error_string(this->Archive);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do not pad the last block!!
|
||||||
|
if (archive_write_set_bytes_in_last_block(this->Archive, 1))
|
||||||
|
{
|
||||||
|
this->Error = "archive_write_set_bytes_in_last_block: ";
|
||||||
|
this->Error += archive_error_string(this->Archive);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(archive_write_open(
|
if(archive_write_open(
|
||||||
this->Archive, this, 0,
|
this->Archive, this, 0,
|
||||||
@ -216,24 +268,24 @@ bool cmArchiveWrite::AddData(const char* file, size_t size)
|
|||||||
size_t nleft = size;
|
size_t nleft = size;
|
||||||
while(nleft > 0)
|
while(nleft > 0)
|
||||||
{
|
{
|
||||||
cmsys_ios::streamsize nnext = static_cast<cmsys_ios::streamsize>(
|
typedef cmsys_ios::streamsize ssize_type;
|
||||||
nleft > sizeof(buffer)? sizeof(buffer) : nleft);
|
size_t const nnext = nleft > sizeof(buffer)? sizeof(buffer) : nleft;
|
||||||
fin.read(buffer, nnext);
|
ssize_type const nnext_s = static_cast<ssize_type>(nnext);
|
||||||
|
fin.read(buffer, nnext_s);
|
||||||
// Some stream libraries (older HPUX) return failure at end of
|
// Some stream libraries (older HPUX) return failure at end of
|
||||||
// file on the last read even if some data were read. Check
|
// file on the last read even if some data were read. Check
|
||||||
// gcount instead of trusting the stream error status.
|
// gcount instead of trusting the stream error status.
|
||||||
if(fin.gcount() != nnext)
|
if(static_cast<size_t>(fin.gcount()) != nnext)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(archive_write_data(this->Archive, buffer,
|
if(archive_write_data(this->Archive, buffer, nnext) != nnext_s)
|
||||||
static_cast<size_t>(nnext)) != nnext)
|
|
||||||
{
|
{
|
||||||
this->Error = "archive_write_data: ";
|
this->Error = "archive_write_data: ";
|
||||||
this->Error += archive_error_string(this->Archive);
|
this->Error += archive_error_string(this->Archive);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nleft -= static_cast<size_t>(nnext);
|
nleft -= nnext;
|
||||||
}
|
}
|
||||||
if(nleft > 0)
|
if(nleft > 0)
|
||||||
{
|
{
|
||||||
|
@ -31,12 +31,22 @@ public:
|
|||||||
enum Compress
|
enum Compress
|
||||||
{
|
{
|
||||||
CompressNone,
|
CompressNone,
|
||||||
|
CompressCompress,
|
||||||
CompressGZip,
|
CompressGZip,
|
||||||
CompressBZip2
|
CompressBZip2,
|
||||||
|
CompressLZMA,
|
||||||
|
CompressXZ
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Archive Type */
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
TypeTAR,
|
||||||
|
TypeZIP
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Construct with output stream to which to write archive. */
|
/** Construct with output stream to which to write archive. */
|
||||||
cmArchiveWrite(std::ostream& os, Compress c = CompressNone);
|
cmArchiveWrite(std::ostream& os, Compress c = CompressNone, Type = TypeTAR);
|
||||||
~cmArchiveWrite();
|
~cmArchiveWrite();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1732,7 +1732,8 @@ bool cmSystemTools::CreateTar(const char* outFileName,
|
|||||||
}
|
}
|
||||||
cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip :
|
cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip :
|
||||||
(bzip2? cmArchiveWrite::CompressBZip2 :
|
(bzip2? cmArchiveWrite::CompressBZip2 :
|
||||||
cmArchiveWrite::CompressNone)));
|
cmArchiveWrite::CompressNone)),
|
||||||
|
cmArchiveWrite::TypeTAR);
|
||||||
a.SetVerbose(verbose);
|
a.SetVerbose(verbose);
|
||||||
for(std::vector<cmStdString>::const_iterator i = files.begin();
|
for(std::vector<cmStdString>::const_iterator i = files.begin();
|
||||||
i != files.end(); ++i)
|
i != files.end(); ++i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user