cmake -E tar: Improve error message formatting

Do not print file paths with our prose line wrapping, which breaks
on spaces.
This commit is contained in:
Brad King
2026-01-15 13:39:13 -05:00
parent 360a822332
commit 6015ef807d
14 changed files with 49 additions and 21 deletions

View File

@@ -448,8 +448,9 @@ bool cmArchiveWrite::AddFile(char const* file, size_t skip, char const* prefix)
cm_archive_entry_copy_pathname(e, dest);
if (archive_read_disk_entry_from_file(this->Disk, e, -1, nullptr) !=
ARCHIVE_OK) {
this->Error = cmStrCat("Unable to read from file '", file,
"': ", cm_archive_error_string(this->Disk));
this->Error =
cmStrCat("Unable to read from file:\n ", file, "\nbecause:\n ",
cm_archive_error_string(this->Disk));
return false;
}
if (!this->MTime.empty()) {

View File

@@ -3901,7 +3901,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args,
parsedArgs.Touch ? cmSystemTools::cmTarExtractTimestamps::No
: cmSystemTools::cmTarExtractTimestamps::Yes,
parsedArgs.Verbose)) {
status.SetError(cmStrCat("failed to extract: ", inFile));
status.SetError(cmStrCat("failed to extract:\n ", inFile));
cmSystemTools::SetFatalErrorOccurred();
return false;
}

View File

@@ -2715,8 +2715,8 @@ bool extract_tar(std::string const& outFileName,
# endif
else {
ArchiveError("Problem with archive_write_header(): ", ext);
cmSystemTools::Error("Current file: " +
cm_archive_entry_pathname(entry));
cmSystemTools::Error(
cmStrCat("Current file:\n ", cm_archive_entry_pathname(entry)));
break;
}
}

View File

@@ -1790,13 +1790,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
if (!cmSystemTools::CreateTar(outFile, files, {}, compress, verbose,
mtime, format, compressionLevel,
numThreads)) {
cmSystemTools::Error("Problem creating tar: " + outFile);
cmSystemTools::Error(cmStrCat("Problem creating tar:\n ", outFile));
return 1;
}
} else if (action == cmSystemTools::TarActionExtract) {
if (!cmSystemTools::ExtractTar(outFile, files, extractTimestamps,
verbose)) {
cmSystemTools::Error("Problem extracting tar: " + outFile);
cmSystemTools::Error(
cmStrCat("Problem extracting tar:\n ", outFile));
return 1;
}
#ifdef _WIN32

View File

@@ -1,2 +1,3 @@
^CMake Error: Zstd is not supported for 7zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it.
CMake Error: Problem creating tar: bad.7z$
CMake Error: Problem creating tar:
bad\.7z$

View File

@@ -1,2 +1,7 @@
^CMake Error: Unable to read from file 'badfile\.txt': .*
CMake Error: Problem creating tar: bad\.tar$
^CMake Error: Unable to read from file:
badfile\.txt
because:
[^
]*
CMake Error: Problem creating tar:
bad\.tar$

View File

@@ -1,2 +1,7 @@
^CMake Error: Unable to read from file 'does-not-exist':.*
CMake Error: Problem creating tar: bad\.tar$
^CMake Error: Unable to read from file:
does-not-exist
because:
[^
]*
CMake Error: Problem creating tar:
bad\.tar$

View File

@@ -1,2 +1,7 @@
^CMake Error: Unable to read from file 'does-not-exist':.*
CMake Error: Problem creating tar: bad\.tar$
^CMake Error: Unable to read from file:
does-not-exist
because:
[^
]*
CMake Error: Problem creating tar:
bad\.tar$

View File

@@ -1,2 +1,3 @@
^CMake Error: unable to parse mtime 'bad'
CMake Error: Problem creating tar: bad\.tar$
CMake Error: Problem creating tar:
bad\.tar$

View File

@@ -1,2 +1,7 @@
^CMake Error: Unable to read from file '--bad':.*
CMake Error: Problem creating tar: bad\.tar$
^CMake Error: Unable to read from file:
--bad
because:
[^
]*
CMake Error: Problem creating tar:
bad\.tar$

View File

@@ -1,2 +1,3 @@
^CMake Error: BZip2 is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it.
CMake Error: Problem creating tar: bad.zip$
CMake Error: Problem creating tar:
bad\.zip$

View File

@@ -1,2 +1,3 @@
^CMake Error: LZMA is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it.
CMake Error: Problem creating tar: bad.zip$
CMake Error: Problem creating tar:
bad\.zip$

View File

@@ -1,2 +1,3 @@
^CMake Error: LZMA2 \(XZ\) is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it.
CMake Error: Problem creating tar: bad.zip$
CMake Error: Problem creating tar:
bad\.zip$

View File

@@ -1,2 +1,3 @@
^CMake Error: Zstd is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it.
CMake Error: Problem creating tar: bad.zip$
CMake Error: Problem creating tar:
bad\.zip$