mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 21:59:54 -06:00
cmake: Don't interrupt archive creation if unable to read a file.
Rationale: Currently during creation of archive by 'tar', if error appears, it interrupt archive creation. As a result only part of files are archived This behaviour is not consistent with 'copy_directory', native 'tar' and other command behaviour. With this Merge Request this behaviour is fixed.
This commit is contained in:
6
Help/release/dev/cmake-e-tar-creating-archive.rst
Normal file
6
Help/release/dev/cmake-e-tar-creating-archive.rst
Normal file
@@ -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.
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,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)
|
||||
|
||||
1
Tests/RunCMake/CommandLineTar/bad-file-result.txt
Normal file
1
Tests/RunCMake/CommandLineTar/bad-file-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
2
Tests/RunCMake/CommandLineTar/bad-file-stderr.txt
Normal file
2
Tests/RunCMake/CommandLineTar/bad-file-stderr.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
^CMake Error: Unable to read from file 'badfile.txt': .*
|
||||
CMake Error: Problem creating tar: bad.tar$
|
||||
@@ -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$
|
||||
|
||||
@@ -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$
|
||||
|
||||
@@ -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$
|
||||
|
||||
0
Tests/RunCMake/CommandLineTar/test-file.txt
Normal file
0
Tests/RunCMake/CommandLineTar/test-file.txt
Normal file
Reference in New Issue
Block a user