aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/tarfile.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-04-15 13:51:00 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-04-15 13:55:22 +0200
commit15f4d4fd437070e898982c510228b6e8eea17b7d (patch)
treecb14c3ea5bcba6165d31083076c575cc2339279f /src/libutil/tarfile.cc
parent6fb75824137de8af12491558c72d2eabc348f6f4 (diff)
Drop libbz2 / zlib / lzma dependency + style fixes
Diffstat (limited to 'src/libutil/tarfile.cc')
-rw-r--r--src/libutil/tarfile.cc37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc
index b5e1cb4c0..24905130d 100644
--- a/src/libutil/tarfile.cc
+++ b/src/libutil/tarfile.cc
@@ -5,38 +5,41 @@
#include "tarfile.hh"
namespace nix {
-static int callback_open(struct archive *, void *self) {
+
+static int callback_open(struct archive *, void * self)
+{
return ARCHIVE_OK;
}
-static ssize_t callback_read(struct archive * archive, void * _self, const void * * buffer) {
- TarArchive *self = (TarArchive *)_self;
+static ssize_t callback_read(struct archive * archive, void * _self, const void * * buffer)
+{
+ auto self = (TarArchive *) _self;
*buffer = self->buffer.data();
try {
return self->source->read((char *) self->buffer.data(), 4096);
} catch (EndOfFile &) {
return 0;
- } catch (std::exception &err) {
+ } catch (std::exception & err) {
archive_set_error(archive, EIO, "Source threw exception: %s", err.what());
-
return -1;
}
}
-static int callback_close(struct archive *, void *self) {
+static int callback_close(struct archive *, void * self)
+{
return ARCHIVE_OK;
}
-void TarArchive::check(int err, const char *reason)
+void TarArchive::check(int err, const std::string & reason)
{
- if (err == ARCHIVE_EOF)
- throw EndOfFile("reached end of archive");
- else if (err != ARCHIVE_OK)
- throw Error(reason, archive_error_string(this->archive));
- }
+ if (err == ARCHIVE_EOF)
+ throw EndOfFile("reached end of archive");
+ else if (err != ARCHIVE_OK)
+ throw Error(reason, archive_error_string(this->archive));
+}
-TarArchive::TarArchive(Source& source, bool raw) : buffer(4096)
+TarArchive::TarArchive(Source & source, bool raw) : buffer(4096)
{
this->archive = archive_read_new();
this->source = &source;
@@ -53,7 +56,7 @@ TarArchive::TarArchive(Source& source, bool raw) : buffer(4096)
}
-TarArchive::TarArchive(const Path &path)
+TarArchive::TarArchive(const Path & path)
{
this->archive = archive_read_new();
@@ -62,11 +65,13 @@ TarArchive::TarArchive(const Path &path)
check(archive_read_open_filename(archive, path.c_str(), 16384), "failed to open archive: %s");
}
-void TarArchive::close() {
+void TarArchive::close()
+{
check(archive_read_close(this->archive), "Failed to close archive (%s)");
}
-TarArchive::~TarArchive() {
+TarArchive::~TarArchive()
+{
if (this->archive) archive_read_free(this->archive);
}