949dc84894
https://hydra.nixos.org/build/107467517 Seems that on i686-linux, gcc and rustc disagree on how to return 1-word structs: gcc has the caller pass a pointer to the result, while rustc has the callee return the result in a register. Work around this by using a bare pointer.
36 lines
1,023 B
C++
36 lines
1,023 B
C++
#include "rust-ffi.hh"
|
|
#include "compression.hh"
|
|
|
|
extern "C" {
|
|
rust::Result<std::tuple<>> *
|
|
unpack_tarfile(rust::Source source, rust::StringSlice dest_dir);
|
|
}
|
|
|
|
namespace nix {
|
|
|
|
void unpackTarfile(Source & source, const Path & destDir)
|
|
{
|
|
rust::Source source2(source);
|
|
rust::CBox(unpack_tarfile(source2, destDir))->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);
|
|
}
|
|
|
|
}
|