diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2009-11-08 00:35:35 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2009-11-08 00:35:35 (GMT) |
commit | 3d1afdee4a0efaf056dbd0581a5e929c91d0f4d7 (patch) | |
tree | e20957358404f5b78f219fde01c97ab216b8e3d4 /Source/cmSystemTools.cxx | |
parent | a73acfbeb9a7d9c73434d2062225cb38e486f12f (diff) | |
download | CMake-3d1afdee4a0efaf056dbd0581a5e929c91d0f4d7.zip CMake-3d1afdee4a0efaf056dbd0581a5e929c91d0f4d7.tar.gz CMake-3d1afdee4a0efaf056dbd0581a5e929c91d0f4d7.tar.bz2 |
add much better error checking on libarchive calls.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index ee6a47e..49a64e7 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1706,7 +1706,18 @@ bool cmSystemTools::CreateTar(const char* outFileName, const std::vector<cmStdString>& files, bool gzip, bool bzip2, bool verbose) { -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if defined(CMAKE_BUILD_WITH_CMAKE) + + // Create a macro to handle return from libarchive + // functions +#define CHECK_ARCHIVE_ERROR(res, msg)\ + if(res != ARCHIVE_OK)\ + {\ + cmSystemTools::Error(msg, \ + archive_error_string(a));\ + return false;\ + } + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); // recursively expand all directories in files so that we have a list // of files @@ -1747,28 +1758,31 @@ bool cmSystemTools::CreateTar(const char* outFileName, int res; // create a new archive struct archive* a = archive_write_new(); + if(!a) + { + cmSystemTools::Error("Unable to use create archive"); + return false; + } + if(gzip) { - res = archive_write_set_compression_gzip(a); - if(res != ARCHIVE_OK) - { - cmSystemTools::Error("Unable to use gzip in libarchive"); - } + res = archive_write_set_compression_gzip(a); + CHECK_ARCHIVE_ERROR(res, "Can not set gzip:"); } if(bzip2) { res = archive_write_set_compression_bzip2(a); - if(res != ARCHIVE_OK) - { - cmSystemTools::Error("Unable to use bzip2 in libarchive"); - } - } - res = archive_write_set_format_ustar(a); - if(res != ARCHIVE_OK) - { - cmSystemTools::Error("Unable to use tar libarchive"); + CHECK_ARCHIVE_ERROR(res, "Can not set bzip2:"); + } + if(!bzip2 && !gzip) + { + res = archive_write_set_compression_none(a); + CHECK_ARCHIVE_ERROR(res, "Can not set none:"); } - archive_write_open_file(a, outFileName); + res = archive_write_set_format_ustar(a); + CHECK_ARCHIVE_ERROR(res, "Can not set tar format:"); + res = archive_write_open_file(a, outFileName); + CHECK_ARCHIVE_ERROR(res, "write open:"); // create a new disk struct struct archive* disk = archive_read_disk_new(); archive_read_disk_set_standard_lookup(disk); @@ -1787,12 +1801,13 @@ bool cmSystemTools::CreateTar(const char* outFileName, } // Set the name of the entry to the file name archive_entry_set_pathname(entry, rp.c_str()); - // get the information about the file from stat - struct stat s; - stat(fileIt->c_str(), &s); - archive_read_disk_entry_from_file(disk, entry, -1, &s); + res = archive_read_disk_entry_from_file(disk, entry, -1, 0); + CHECK_ARCHIVE_ERROR(res, "read disk entry:"); + // write entry header - archive_write_header(a, entry); + res = archive_write_header(a, entry); + CHECK_ARCHIVE_ERROR(res, "write header: "); + // now copy contents of file into archive a FILE* file = fopen(fileIt->c_str(), "rb"); if(!file) @@ -1805,7 +1820,14 @@ bool cmSystemTools::CreateTar(const char* outFileName, int len = fread(buff, 1, sizeof(buff), file); while (len > 0) { - archive_write_data(a, buff, len); + int wlen = archive_write_data(a, buff, len); + if(wlen != len) + { + cmSystemTools::Error("Problem with archive_write_data:", + archive_error_string(a) + ); + return false; + } len = fread(buff, 1, sizeof(buff), file); } // close the file and free the entry |