aboutsummaryrefslogtreecommitdiff
path: root/src/nix/test.cc
blob: 70e0a903de4cfb07483b622c335d1b37c683f76b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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<typename T> struct Slice
{
    const T * ptr;
    size_t size;

    Slice(const T * ptr, size_t size) : ptr(ptr), size(size)
    {
        assert(ptr);
    }
};

struct StringSlice : Slice<char>
{
    StringSlice(const std::string & s): Slice(s.data(), s.size()) { }
};

}

extern "C" {
    bool unpack_tarfile(rust::Slice<uint8_t> 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> 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<CmdTest>());