diff options
-rw-r--r-- | Help/manual/cmake.1.rst | 15 | ||||
-rw-r--r-- | Help/release/dev/cmake-e-tar-creating-archive.rst | 6 | ||||
-rw-r--r-- | Source/cmArchiveWrite.cxx | 11 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 10 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 4 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake | 10 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/bad-file-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/bad-file-stderr.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/test-file.txt | 0 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLineTar/without-files-stderr.txt | 1 |
14 files changed, 48 insertions, 19 deletions
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index a3c7834..db035c2 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -483,6 +483,21 @@ Available commands are: ``tar [cxt][vf][zjJ] file.tar [<options>] [--] [<file>...]`` Create or extract a tar or zip archive. Options are: + ``c`` + Create a new archive containing the specified files. + If used, the <file> argument is mandatory. + ``x`` + Extract to disk from the archive. + ``t`` + List archive contents to stdout. + ``v`` + Produce verbose output. + ``z`` + Compress the resulting archive with gzip. + ``j`` + Compress the resulting archive with bzip2. + ``J`` + Compress the resulting archive with XZ. ``--`` Stop interpreting options and treat all remaining arguments as file names even if they start in ``-``. diff --git a/Help/release/dev/cmake-e-tar-creating-archive.rst b/Help/release/dev/cmake-e-tar-creating-archive.rst new file mode 100644 index 0000000..717855c --- /dev/null +++ b/Help/release/dev/cmake-e-tar-creating-archive.rst @@ -0,0 +1,6 @@ +cmake-e-tar-creating-archive +---------------------------- + +* The :manual:`cmake(1)` ``-E tar`` tool now continues adding files to an + archive, even if some of the files aren't readable. This behavior is more + consistent with the classic ``tar`` tool. diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 23be603..177ba02 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -179,12 +179,10 @@ cmArchiveWrite::~cmArchiveWrite() bool cmArchiveWrite::Add(std::string path, size_t skip, const char* prefix, bool recursive) { - if (this->Okay()) { - if (!path.empty() && path.back() == '/') { - path.erase(path.size() - 1); - } - this->AddPath(path.c_str(), skip, prefix, recursive); + if (!path.empty() && path.back() == '/') { + path.erase(path.size() - 1); } + this->AddPath(path.c_str(), skip, prefix, recursive); return this->Okay(); } @@ -220,6 +218,7 @@ bool cmArchiveWrite::AddPath(const char* path, size_t skip, const char* prefix, bool cmArchiveWrite::AddFile(const char* file, size_t skip, const char* prefix) { + this->Error = ""; // Skip the file if we have no name for it. This may happen on a // top-level directory, which does not need to be included anyway. if (skip >= strlen(file)) { @@ -241,7 +240,7 @@ bool cmArchiveWrite::AddFile(const char* file, size_t skip, const char* prefix) cm_archive_entry_copy_pathname(e, dest); if (archive_read_disk_entry_from_file(this->Disk, e, -1, nullptr) != ARCHIVE_OK) { - this->Error = "archive_read_disk_entry_from_file '"; + this->Error = "Unable to read from file '"; this->Error += file; this->Error += "': "; this->Error += cm_archive_error_string(this->Disk); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index d762106..41f8cf4 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1658,20 +1658,18 @@ bool cmSystemTools::CreateTar(const char* outFileName, a.SetMTime(mtime); a.SetVerbose(verbose); + bool tarCreatedSuccessfully = true; for (auto path : files) { if (cmSystemTools::FileIsFullPath(path)) { // Get the relative path to the file. path = cmSystemTools::RelativePath(cwd, path); } if (!a.Add(path)) { - break; + cmSystemTools::Error(a.GetError()); + tarCreatedSuccessfully = false; } } - if (!a) { - cmSystemTools::Error(a.GetError()); - return false; - } - return true; + return tarCreatedSuccessfully; #else (void)outFileName; (void)files; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index f996a3e..0828a16 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1114,6 +1114,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) return 1; } } else if (flags.find_first_of('c') != std::string::npos) { + if (files.empty()) { + cmSystemTools::Message("tar: No files or directories specified", + "Warning"); + } if (!cmSystemTools::CreateTar(outFile.c_str(), files, compress, verbose, mtime, format)) { cmSystemTools::Error("Problem creating tar: " + outFile); diff --git a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake index 12635db..c8a3de9 100644 --- a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake @@ -4,6 +4,7 @@ function(external_command_test NAME) run_cmake_command(${NAME} ${CMAKE_COMMAND} -E ${ARGN}) endfunction() +external_command_test(without-files tar cvf bad.tar) external_command_test(bad-opt1 tar cvf bad.tar --bad) external_command_test(bad-mtime1 tar cvf bad.tar --mtime=bad .) external_command_test(bad-from1 tar cvf bad.tar --files-from=bad) @@ -11,12 +12,13 @@ external_command_test(bad-from2 tar cvf bad.tar --files-from=.) external_command_test(bad-from3 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from3.txt) external_command_test(bad-from4 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from4.txt) external_command_test(bad-from5 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from5.txt) +external_command_test(bad-file tar cf bad.tar badfile.txt ${CMAKE_CURRENT_LIST_DIR}/test-file.txt) external_command_test(end-opt1 tar cvf bad.tar -- --bad) external_command_test(end-opt2 tar cvf bad.tar --) -external_command_test(mtime tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC") -external_command_test(bad-format tar cvf bad.tar "--format=bad-format") -external_command_test(zip-bz2 tar cvjf bad.tar "--format=zip") -external_command_test(7zip-gz tar cvzf bad.tar "--format=7zip") +external_command_test(mtime tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt) +external_command_test(bad-format tar cvf bad.tar "--format=bad-format" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt) +external_command_test(zip-bz2 tar cvjf bad.tar "--format=zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt) +external_command_test(7zip-gz tar cvzf bad.tar "--format=7zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt) run_cmake(7zip) run_cmake(gnutar) diff --git a/Tests/RunCMake/CommandLineTar/bad-file-result.txt b/Tests/RunCMake/CommandLineTar/bad-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLineTar/bad-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLineTar/bad-file-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-file-stderr.txt new file mode 100644 index 0000000..1f9f748 --- /dev/null +++ b/Tests/RunCMake/CommandLineTar/bad-file-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error: Unable to read from file 'badfile.txt': .* +CMake Error: Problem creating tar: bad.tar$ diff --git a/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt index 1417d4d..fb0702a 100644 --- a/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt @@ -1,2 +1,2 @@ -^CMake Error: archive_read_disk_entry_from_file 'does-not-exist':.* +^CMake Error: Unable to read from file 'does-not-exist':.* CMake Error: Problem creating tar: bad.tar$ diff --git a/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt index 1417d4d..fb0702a 100644 --- a/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt @@ -1,2 +1,2 @@ -^CMake Error: archive_read_disk_entry_from_file 'does-not-exist':.* +^CMake Error: Unable to read from file 'does-not-exist':.* CMake Error: Problem creating tar: bad.tar$ diff --git a/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt b/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt index 1fddf6d..1342dc8 100644 --- a/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt @@ -1,2 +1,2 @@ -^CMake Error: archive_read_disk_entry_from_file '--bad':.* +^CMake Error: Unable to read from file '--bad':.* CMake Error: Problem creating tar: bad.tar$ diff --git a/Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt b/Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt new file mode 100644 index 0000000..70166f5 --- /dev/null +++ b/Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt @@ -0,0 +1 @@ +^tar: No files or directories specified diff --git a/Tests/RunCMake/CommandLineTar/test-file.txt b/Tests/RunCMake/CommandLineTar/test-file.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/CommandLineTar/test-file.txt diff --git a/Tests/RunCMake/CommandLineTar/without-files-stderr.txt b/Tests/RunCMake/CommandLineTar/without-files-stderr.txt new file mode 100644 index 0000000..70166f5 --- /dev/null +++ b/Tests/RunCMake/CommandLineTar/without-files-stderr.txt @@ -0,0 +1 @@ +^tar: No files or directories specified |