1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-23 02:39:37 +01:00

Make <nix/unpack-channel.nix> a builtin builder

This was the last function using a shell script, so this allows us to
get rid of tar, coreutils, bash etc.
This commit is contained in:
Eelco Dolstra 2019-03-27 23:40:35 +01:00
parent e60f6bd4ce
commit 045708db43
9 changed files with 55 additions and 84 deletions

44
src/libstore/rust.hh Normal file
View file

@ -0,0 +1,44 @@
#include "serialise.hh"
namespace rust {
// Depending on the internal representation of Rust slices is slightly
// evil...
template<typename T> struct Slice
{
T * ptr;
size_t size;
Slice(T * ptr, size_t size) : ptr(ptr), size(size)
{
assert(ptr);
}
};
struct StringSlice : Slice<char>
{
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;
}
};
}
extern "C" {
bool unpack_tarfile(rust::Source source, rust::StringSlice dest_dir);
}