Revert "TarArchive: Small refactoring"

This reverts commit 50a35860ee.

With this change Nix fails to open bzip2 logfiles that were created from
builds with no stdout/stderr.
This commit is contained in:
Maximilian Bosch 2022-02-06 14:47:07 +01:00
parent d9cfd853e5
commit c85467a1b6
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
2 changed files with 14 additions and 15 deletions

View file

@ -39,30 +39,32 @@ void TarArchive::check(int err, const std::string & reason)
throw Error(reason, archive_error_string(this->archive)); throw Error(reason, archive_error_string(this->archive));
} }
TarArchive::TarArchive(Source & source, bool raw) TarArchive::TarArchive(Source & source, bool raw) : buffer(4096)
: source(&source), buffer(4096)
{ {
init(); this->archive = archive_read_new();
if (!raw) this->source = &source;
if (!raw) {
archive_read_support_filter_all(archive);
archive_read_support_format_all(archive); archive_read_support_format_all(archive);
else } else {
archive_read_support_filter_all(archive);
archive_read_support_format_raw(archive); archive_read_support_format_raw(archive);
archive_read_support_format_empty(archive);
}
check(archive_read_open(archive, (void *)this, callback_open, callback_read, callback_close), "Failed to open archive (%s)"); check(archive_read_open(archive, (void *)this, callback_open, callback_read, callback_close), "Failed to open archive (%s)");
} }
TarArchive::TarArchive(const Path & path) TarArchive::TarArchive(const Path & path)
{ {
init(); this->archive = archive_read_new();
archive_read_support_filter_all(archive);
archive_read_support_format_all(archive); archive_read_support_format_all(archive);
check(archive_read_open_filename(archive, path.c_str(), 16384), "failed to open archive: %s"); check(archive_read_open_filename(archive, path.c_str(), 16384), "failed to open archive: %s");
} }
void TarArchive::init()
{
archive = archive_read_new();
archive_read_support_filter_all(archive);
}
void TarArchive::close() void TarArchive::close()
{ {
check(archive_read_close(this->archive), "Failed to close archive (%s)"); check(archive_read_close(this->archive), "Failed to close archive (%s)");

View file

@ -17,13 +17,10 @@ struct TarArchive {
// disable copy constructor // disable copy constructor
TarArchive(const TarArchive &) = delete; TarArchive(const TarArchive &) = delete;
void init();
void close(); void close();
~TarArchive(); ~TarArchive();
}; };
void unpackTarfile(Source & source, const Path & destDir); void unpackTarfile(Source & source, const Path & destDir);
void unpackTarfile(const Path & tarFile, const Path & destDir); void unpackTarfile(const Path & tarFile, const Path & destDir);