aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/tarfile.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/tarfile.cc')
-rw-r--r--src/libutil/tarfile.cc22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc
index ae6d512bd..f7d3ad417 100644
--- a/src/libutil/tarfile.cc
+++ b/src/libutil/tarfile.cc
@@ -1,4 +1,5 @@
#include "rust-ffi.hh"
+#include "compression.hh"
extern "C" {
rust::CBox2<rust::Result<std::tuple<>>> unpack_tarfile(rust::Source source, rust::StringSlice dest_dir);
@@ -6,9 +7,28 @@ extern "C" {
namespace nix {
-void unpackTarfile(Source & source, Path destDir)
+void unpackTarfile(Source & source, const Path & destDir)
{
unpack_tarfile(source, destDir).use()->unwrap();
}
+void unpackTarfile(const Path & tarFile, const Path & destDir,
+ std::optional<std::string> baseName)
+{
+ if (!baseName) baseName = baseNameOf(tarFile);
+
+ auto source = sinkToSource([&](Sink & sink) {
+ // FIXME: look at first few bytes to determine compression type.
+ auto decompressor =
+ // FIXME: add .gz support
+ hasSuffix(*baseName, ".bz2") ? makeDecompressionSink("bzip2", sink) :
+ hasSuffix(*baseName, ".xz") ? makeDecompressionSink("xz", sink) :
+ makeDecompressionSink("none", sink);
+ readFile(tarFile, *decompressor);
+ decompressor->finish();
+ });
+
+ unpackTarfile(*source, destDir);
+}
+
}