From 11da5b2816e11b081d8ff38db4330addd2014f7e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 27 Mar 2019 14:12:20 +0100 Subject: Add some Rust code --- src/nix/test.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/nix/test.cc (limited to 'src/nix/test.cc') diff --git a/src/nix/test.cc b/src/nix/test.cc new file mode 100644 index 000000000..70e0a903d --- /dev/null +++ b/src/nix/test.cc @@ -0,0 +1,61 @@ +#include "command.hh" +#include "store-api.hh" +#include "common-args.hh" + +using namespace nix; + +namespace rust { + +// Depending on the internal representation of Rust slices is slightly +// evil... +template struct Slice +{ + const T * ptr; + size_t size; + + Slice(const T * ptr, size_t size) : ptr(ptr), size(size) + { + assert(ptr); + } +}; + +struct StringSlice : Slice +{ + StringSlice(const std::string & s): Slice(s.data(), s.size()) { } +}; + +} + +extern "C" { + bool unpack_tarfile(rust::Slice data, rust::StringSlice dest_dir); +} + +struct CmdTest : StoreCommand +{ + CmdTest() + { + } + + std::string name() override + { + return "test"; + } + + std::string description() override + { + return "bla bla"; + } + + void run(ref store) override + { + auto data = readFile("./nix-2.2.tar"); + + std::string destDir = "./dest"; + + deletePath(destDir); + + unpack_tarfile({(uint8_t*) data.data(), data.size()}, destDir); + } +}; + +static RegisterCommand r(make_ref()); -- cgit v1.2.3