2019-09-11 12:43:07 +02:00
|
|
|
#include "rust-ffi.hh"
|
2019-09-11 15:25:43 +02:00
|
|
|
#include "compression.hh"
|
2019-03-27 14:12:20 +01:00
|
|
|
|
|
|
|
extern "C" {
|
2019-11-27 14:17:15 +01:00
|
|
|
rust::Result<std::tuple<>> *
|
|
|
|
unpack_tarfile(rust::Source source, rust::StringSlice dest_dir);
|
2019-03-27 14:12:20 +01:00
|
|
|
}
|
2019-09-11 13:10:46 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2019-09-11 15:25:43 +02:00
|
|
|
void unpackTarfile(Source & source, const Path & destDir)
|
2019-09-11 13:10:46 +02:00
|
|
|
{
|
2019-11-27 14:17:15 +01:00
|
|
|
rust::Source source2(source);
|
|
|
|
rust::CBox(unpack_tarfile(source2, destDir))->unwrap();
|
2019-09-11 13:10:46 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 15:25:43 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-09-11 13:10:46 +02:00
|
|
|
}
|