mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 08:51:52 +08:00
cmArchiveWrite: split out opening the file
This allows options to be set before the "header" phase of libarchive's API.
This commit is contained in:
@@ -154,6 +154,13 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(
|
|||||||
} \
|
} \
|
||||||
cmArchiveWrite archive(gf, this->Compress, this->ArchiveFormat); \
|
cmArchiveWrite archive(gf, this->Compress, this->ArchiveFormat); \
|
||||||
do { \
|
do { \
|
||||||
|
if (!archive.Open()) { \
|
||||||
|
cmCPackLogger(cmCPackLog::LOG_ERROR, \
|
||||||
|
"Problem to open archive <" \
|
||||||
|
<< (filename) << ">, ERROR = " << (archive).GetError() \
|
||||||
|
<< std::endl); \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
if (!(archive)) { \
|
if (!(archive)) { \
|
||||||
cmCPackLogger(cmCPackLog::LOG_ERROR, \
|
cmCPackLogger(cmCPackLog::LOG_ERROR, \
|
||||||
"Problem to create archive <" \
|
"Problem to create archive <" \
|
||||||
|
@@ -173,6 +173,7 @@ bool DebGenerator::generateDataTar() const
|
|||||||
}
|
}
|
||||||
cmArchiveWrite data_tar(fileStream_data_tar, TarCompressionType,
|
cmArchiveWrite data_tar(fileStream_data_tar, TarCompressionType,
|
||||||
DebianArchiveType);
|
DebianArchiveType);
|
||||||
|
data_tar.Open();
|
||||||
|
|
||||||
// uid/gid should be the one of the root user, and this root user has
|
// uid/gid should be the one of the root user, and this root user has
|
||||||
// always uid/gid equal to 0.
|
// always uid/gid equal to 0.
|
||||||
@@ -291,6 +292,7 @@ bool DebGenerator::generateControlTar(std::string const& md5Filename) const
|
|||||||
}
|
}
|
||||||
cmArchiveWrite control_tar(fileStream_control_tar,
|
cmArchiveWrite control_tar(fileStream_control_tar,
|
||||||
cmArchiveWrite::CompressGZip, DebianArchiveType);
|
cmArchiveWrite::CompressGZip, DebianArchiveType);
|
||||||
|
control_tar.Open();
|
||||||
|
|
||||||
// sets permissions and uid/gid for the files
|
// sets permissions and uid/gid for the files
|
||||||
control_tar.SetUIDAndGID(0u, 0u);
|
control_tar.SetUIDAndGID(0u, 0u);
|
||||||
@@ -410,6 +412,7 @@ bool DebGenerator::generateDeb() const
|
|||||||
cmGeneratedFileStream debStream;
|
cmGeneratedFileStream debStream;
|
||||||
debStream.Open(outputPath, false, true);
|
debStream.Open(outputPath, false, true);
|
||||||
cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd");
|
cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd");
|
||||||
|
deb.Open();
|
||||||
|
|
||||||
// uid/gid should be the one of the root user, and this root user has
|
// uid/gid should be the one of the root user, and this root user has
|
||||||
// always uid/gid equal to 0.
|
// always uid/gid equal to 0.
|
||||||
|
@@ -170,15 +170,19 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c,
|
|||||||
cm_archive_error_string(this->Archive));
|
cm_archive_error_string(this->Archive));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cmArchiveWrite::Open()
|
||||||
|
{
|
||||||
if (archive_write_open(
|
if (archive_write_open(
|
||||||
this->Archive, this, nullptr,
|
this->Archive, this, nullptr,
|
||||||
reinterpret_cast<archive_write_callback*>(&Callback::Write),
|
reinterpret_cast<archive_write_callback*>(&Callback::Write),
|
||||||
nullptr) != ARCHIVE_OK) {
|
nullptr) != ARCHIVE_OK) {
|
||||||
this->Error =
|
this->Error =
|
||||||
cmStrCat("archive_write_open: ", cm_archive_error_string(this->Archive));
|
cmStrCat("archive_write_open: ", cm_archive_error_string(this->Archive));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmArchiveWrite::~cmArchiveWrite()
|
cmArchiveWrite::~cmArchiveWrite()
|
||||||
|
@@ -62,6 +62,8 @@ public:
|
|||||||
cmArchiveWrite(const cmArchiveWrite&) = delete;
|
cmArchiveWrite(const cmArchiveWrite&) = delete;
|
||||||
cmArchiveWrite& operator=(const cmArchiveWrite&) = delete;
|
cmArchiveWrite& operator=(const cmArchiveWrite&) = delete;
|
||||||
|
|
||||||
|
bool Open();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a path (file or directory) to the archive. Directories are
|
* Add a path (file or directory) to the archive. Directories are
|
||||||
* added recursively. The "path" must be readable on disk, either
|
* added recursively. The "path" must be readable on disk, either
|
||||||
|
@@ -1312,6 +1312,7 @@ bool cmSystemTools::CreateTar(const std::string& outFileName,
|
|||||||
|
|
||||||
cmArchiveWrite a(fout, compress, format.empty() ? "paxr" : format);
|
cmArchiveWrite a(fout, compress, format.empty() ? "paxr" : format);
|
||||||
|
|
||||||
|
a.Open();
|
||||||
a.SetMTime(mtime);
|
a.SetMTime(mtime);
|
||||||
a.SetVerbose(verbose);
|
a.SetVerbose(verbose);
|
||||||
bool tarCreatedSuccessfully = true;
|
bool tarCreatedSuccessfully = true;
|
||||||
|
Reference in New Issue
Block a user