[Cmake-commits] [cmake-commits] hoffman committed cmSystemTools.cxx 1.411 1.412
cmake-commits at cmake.org
cmake-commits at cmake.org
Sat Nov 7 19:35:37 EST 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv32639
Modified Files:
cmSystemTools.cxx
Log Message:
add much better error checking on libarchive calls.
Index: cmSystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v
retrieving revision 1.411
retrieving revision 1.412
diff -C 2 -d -r1.411 -r1.412
*** cmSystemTools.cxx 5 Nov 2009 21:14:46 -0000 1.411
--- cmSystemTools.cxx 8 Nov 2009 00:35:35 -0000 1.412
***************
*** 1707,1711 ****
bool gzip, bool bzip2, bool verbose)
{
! #if defined(CMAKE_BUILD_WITH_CMAKE)
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
// recursively expand all directories in files so that we have a list
--- 1707,1722 ----
bool gzip, bool bzip2, bool verbose)
{
! #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
***************
*** 1748,1773 ****
// create a new archive
struct archive* a = archive_write_new();
if(gzip)
{
! res = archive_write_set_compression_gzip(a);
! if(res != ARCHIVE_OK)
! {
! cmSystemTools::Error("Unable to use gzip in libarchive");
! }
}
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");
}
! archive_write_open_file(a, outFileName);
// create a new disk struct
struct archive* disk = archive_read_disk_new();
--- 1759,1787 ----
// 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);
! CHECK_ARCHIVE_ERROR(res, "Can not set gzip:");
}
if(bzip2)
{
res = archive_write_set_compression_bzip2(a);
! 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:");
! }
! 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();
***************
*** 1788,1797 ****
// 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);
// write entry header
! archive_write_header(a, entry);
// now copy contents of file into archive a
FILE* file = fopen(fileIt->c_str(), "rb");
--- 1802,1812 ----
// Set the name of the entry to the file name
archive_entry_set_pathname(entry, rp.c_str());
! res = archive_read_disk_entry_from_file(disk, entry, -1, 0);
! CHECK_ARCHIVE_ERROR(res, "read disk entry:");
!
// write entry header
! 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");
***************
*** 1806,1810 ****
while (len > 0)
{
! archive_write_data(a, buff, len);
len = fread(buff, 1, sizeof(buff), file);
}
--- 1821,1832 ----
while (len > 0)
{
! 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);
}
More information about the Cmake-commits
mailing list