From 4663356079da1c578ab0f7762b4c9d87327b80c3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 11 Aug 2010 09:47:04 -0400 Subject: [PATCH 1/4] cmArchiveWrite: Fix signed/unsigned again Some stream libraries return size_t from gcount() and some return ssize_t. Add an explicit cast to ios::streamsize for its return value. Also refactor use of nnext to reduce the use of casts. --- Source/cmArchiveWrite.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 88874aa6e..94c97e64e 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -216,24 +216,24 @@ bool cmArchiveWrite::AddData(const char* file, size_t size) size_t nleft = size; while(nleft > 0) { - cmsys_ios::streamsize nnext = static_cast( - nleft > sizeof(buffer)? sizeof(buffer) : nleft); - fin.read(buffer, nnext); + typedef cmsys_ios::streamsize ssize_type; + size_t const nnext = nleft > sizeof(buffer)? sizeof(buffer) : nleft; + ssize_type const nnext_s = static_cast(nnext); + fin.read(buffer, nnext_s); // Some stream libraries (older HPUX) return failure at end of // file on the last read even if some data were read. Check // gcount instead of trusting the stream error status. - if(fin.gcount() != nnext) + if(static_cast(fin.gcount()) != nnext) { break; } - if(archive_write_data(this->Archive, buffer, - static_cast(nnext)) != nnext) + if(archive_write_data(this->Archive, buffer, nnext) != nnext_s) { this->Error = "archive_write_data: "; this->Error += archive_error_string(this->Archive); return false; } - nleft -= static_cast(nnext); + nleft -= nnext; } if(nleft > 0) { From b50c15915ac5cca79e00bf438dacd074fe531978 Mon Sep 17 00:00:00 2001 From: Eric NOULARD Date: Fri, 13 Aug 2010 17:49:47 +0200 Subject: [PATCH 2/4] Add ZIP archive format and LZMA compress support to libarchive-wrapper This will be needed to use cmArchiveWrire in cmCPackArchiveGenerator with the same feature set as before. Note that adding zip support to libarchive-wrapper would also makes it easy to add a new -E zip command to cmake commands. --- Source/cmArchiveWrite.cxx | 44 +++++++++++++++++++++++++++++++++++---- Source/cmArchiveWrite.h | 12 +++++++++-- Source/cmSystemTools.cxx | 3 ++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 94c97e64e..bea958612 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -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), Archive(archive_write_new()), Disk(archive_read_disk_new()), @@ -79,11 +79,47 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c): return; } 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; }; - archive_read_disk_set_standard_lookup(this->Disk); - if(archive_write_set_format_pax_restricted(this->Archive) != ARCHIVE_OK) +#if !defined(_WIN32) || defined(__CYGWIN__) + if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK) { - this->Error = "archive_write_set_format_pax_restricted: "; + 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) + { + this->Error = "archive_write_set_format_pax_restricted: "; + this->Error += archive_error_string(this->Archive); + 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; } diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h index 92c0c7320..0bd3e9b00 100644 --- a/Source/cmArchiveWrite.h +++ b/Source/cmArchiveWrite.h @@ -32,11 +32,19 @@ public: { CompressNone, CompressGZip, - CompressBZip2 + CompressBZip2, + CompressLZMA + }; + + /** Archive Type */ + enum Type + { + TypeTAR, + TypeZIP }; /** 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(); /** diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index a26452c87..0e0a770f7 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1732,7 +1732,8 @@ bool cmSystemTools::CreateTar(const char* outFileName, } cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip : (bzip2? cmArchiveWrite::CompressBZip2 : - cmArchiveWrite::CompressNone))); + cmArchiveWrite::CompressNone)), + cmArchiveWrite::TypeTAR); a.SetVerbose(verbose); for(std::vector::const_iterator i = files.begin(); i != files.end(); ++i) From 1a3ad5c615be02cd18fe8e166b16ee15f821df72 Mon Sep 17 00:00:00 2001 From: Eric NOULARD Date: Fri, 13 Aug 2010 17:51:27 +0200 Subject: [PATCH 3/4] Add XZ compress support to libarchive-wrapper This is not needed but it does not cost much to do it for all potentially supported format in libarchive. XZ and LZMA are not builtin libarchive and require external lib but if CMAKE_USE_SYSTEM_LIBARCHIVE is ON then we may get it for free. --- Source/cmArchiveWrite.cxx | 8 ++++++++ Source/cmArchiveWrite.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index bea958612..524e53ed6 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -87,6 +87,14 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t): 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; }; #if !defined(_WIN32) || defined(__CYGWIN__) if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK) diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h index 0bd3e9b00..ce7f961c6 100644 --- a/Source/cmArchiveWrite.h +++ b/Source/cmArchiveWrite.h @@ -33,7 +33,8 @@ public: CompressNone, CompressGZip, CompressBZip2, - CompressLZMA + CompressLZMA, + CompressXZ }; /** Archive Type */ From fb41da4a6b648966e518cbe388b82bcde74f038e Mon Sep 17 00:00:00 2001 From: Eric NOULARD Date: Mon, 16 Aug 2010 20:45:05 +0200 Subject: [PATCH 4/4] Add Compress compress support to libarchive-wrapper --- Source/cmArchiveWrite.cxx | 8 ++++++++ Source/cmArchiveWrite.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 524e53ed6..d9e4742a2 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -63,6 +63,14 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t): return; } 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: if(archive_write_set_compression_gzip(this->Archive) != ARCHIVE_OK) { diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h index ce7f961c6..3e3b2f0ca 100644 --- a/Source/cmArchiveWrite.h +++ b/Source/cmArchiveWrite.h @@ -31,6 +31,7 @@ public: enum Compress { CompressNone, + CompressCompress, CompressGZip, CompressBZip2, CompressLZMA,