2019-03-27 15:12:20 +02:00
|
|
|
#include "command.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
#include "common-args.hh"
|
2019-03-27 21:45:56 +02:00
|
|
|
#include "compression.hh"
|
2019-03-27 15:12:20 +02:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
namespace rust {
|
|
|
|
|
|
|
|
// Depending on the internal representation of Rust slices is slightly
|
|
|
|
// evil...
|
|
|
|
template<typename T> struct Slice
|
|
|
|
{
|
2019-03-27 21:45:56 +02:00
|
|
|
T * ptr;
|
2019-03-27 15:12:20 +02:00
|
|
|
size_t size;
|
|
|
|
|
2019-03-27 21:45:56 +02:00
|
|
|
Slice(T * ptr, size_t size) : ptr(ptr), size(size)
|
2019-03-27 15:12:20 +02:00
|
|
|
{
|
|
|
|
assert(ptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StringSlice : Slice<char>
|
|
|
|
{
|
2019-03-27 21:45:56 +02:00
|
|
|
StringSlice(const std::string & s): Slice((char *) s.data(), s.size()) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Source
|
|
|
|
{
|
|
|
|
size_t (*fun)(void * source_this, rust::Slice<uint8_t> data);
|
|
|
|
nix::Source * _this;
|
|
|
|
|
|
|
|
Source(nix::Source & _this)
|
|
|
|
: fun(sourceWrapper), _this(&_this)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// FIXME: how to propagate exceptions?
|
|
|
|
static size_t sourceWrapper(void * _this, rust::Slice<uint8_t> data)
|
|
|
|
{
|
|
|
|
auto n = ((nix::Source *) _this)->read(data.ptr, data.size);
|
|
|
|
return n;
|
|
|
|
}
|
2019-03-27 15:12:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
2019-03-27 21:45:56 +02:00
|
|
|
bool unpack_tarfile(rust::Source source, rust::StringSlice dest_dir);
|
2019-03-27 15:12:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct CmdTest : StoreCommand
|
|
|
|
{
|
|
|
|
CmdTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string name() override
|
|
|
|
{
|
|
|
|
return "test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string description() override
|
|
|
|
{
|
|
|
|
return "bla bla";
|
|
|
|
}
|
|
|
|
|
|
|
|
void run(ref<Store> store) override
|
|
|
|
{
|
2019-03-27 21:45:56 +02:00
|
|
|
auto source = sinkToSource([&](Sink & sink) {
|
|
|
|
auto decompressor = makeDecompressionSink("bzip2", sink);
|
|
|
|
readFile("./nix-2.2.tar.bz2", *decompressor);
|
|
|
|
decompressor->finish();
|
|
|
|
});
|
2019-03-27 15:12:20 +02:00
|
|
|
|
|
|
|
std::string destDir = "./dest";
|
|
|
|
|
|
|
|
deletePath(destDir);
|
|
|
|
|
2019-03-27 21:45:56 +02:00
|
|
|
unpack_tarfile(*source, destDir);
|
2019-03-27 15:12:20 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static RegisterCommand r(make_ref<CmdTest>());
|