From a203fcc63d3e11a44c51f818710bb304c1b6f780 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Wed, 16 May 2018 23:44:56 +0300 Subject: cmake: Teach '-E tar' to report errors copying data The `copy_data` function checks for errors but the caller ignored them. Simplify its return type and add a check to the caller. --- Source/cmSystemTools.cxx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 94c5ee8..169b525 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1696,7 +1696,8 @@ void list_item_verbose(FILE* out, struct archive_entry* entry) fflush(out); } -long copy_data(struct archive* ar, struct archive* aw) +// Return 'true' on success +bool copy_data(struct archive* ar, struct archive* aw) { long r; const void* buff; @@ -1708,22 +1709,28 @@ long copy_data(struct archive* ar, struct archive* aw) #endif for (;;) { + // Return value: + // * ARCHIVE_OK - read succeed + // * ARCHIVE_EOF - no more data to read left r = archive_read_data_block(ar, &buff, &size, &offset); if (r == ARCHIVE_EOF) { - return (ARCHIVE_OK); + return true; } if (r != ARCHIVE_OK) { - return (r); + return false; } - r = archive_write_data_block(aw, buff, size, offset); - if (r != ARCHIVE_OK) { + // Return value: + // * >= ARCHIVE_OK - write succeed + // * < ARCHIVE_OK - write failed + const la_ssize_t w_size = archive_write_data_block(aw, buff, size, offset); + if (w_size < ARCHIVE_OK) { cmSystemTools::Message("archive_write_data_block()", archive_error_string(aw)); - return (r); + return false; } } #if !defined(__clang__) && !defined(__HP_aCC) - return r; /* this should not happen but it quiets some compilers */ + return false; /* this should not happen but it quiets some compilers */ #endif } @@ -1776,7 +1783,10 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) r = archive_write_header(ext, entry); if (r == ARCHIVE_OK) { - copy_data(a, ext); + if (!copy_data(a, ext)) { + cmSystemTools::Error("Problem with copy_data"); + break; + } r = archive_write_finish_entry(ext); if (r != ARCHIVE_OK) { cmSystemTools::Error("Problem with archive_write_finish_entry(): ", -- cgit v0.12