From 232b39076688c0720f0b5d567cd2a2ac1061c676 Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Sat, 7 Dec 2019 23:00:37 +0700 Subject: [PATCH] fixup! libarchive proof of concept --- src/libutil/tarfile.cc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc index ab30002dd..6c3fb4634 100644 --- a/src/libutil/tarfile.cc +++ b/src/libutil/tarfile.cc @@ -61,11 +61,11 @@ static void copy_data(std::shared_ptr ar, std::shared_ptr ar, std::shared_ptr a, const Path & destDir) { char * cwd = getcwd(0, 0); if (!cwd) throw SysError("getting current directory"); - Finally freeCwd([&]() { free(cwd); }); + Finally freeCwd([&]() { chdir(cwd); free(cwd); }); int r = chdir(destDir.c_str()); if (r != 0) throw SysError("setting directory to tar output path"); struct archive_entry *entry; - r = archive_read_next_header(a.get(), &entry); - if (r != ARCHIVE_OK) { - throw Error("archive is corrupt (%s)", archive_error_string(a.get())); - } int flags = 0; auto ext = archive_write_ptr(); flags |= ARCHIVE_EXTRACT_PERM; @@ -100,13 +96,10 @@ static void extract_archive(std::shared_ptr a, const Path & dest if (r != ARCHIVE_OK) { throw Error("could not write archive output (%s)", archive_error_string(ext.get())); } - if (archive_entry_size(entry) > 0) { - copy_data(a, ext); - } + copy_data(a, ext); archive_write_finish_entry(ext.get()); } - r = chdir(cwd); - if (r != 0) throw SysError("resetting directory after archive extraction"); + //if (r != 0) throw SysError("resetting directory after archive extraction"); } void unpackTarfile(Source & source, const Path & destDir) {