2019-12-05 20:11:09 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "rust-ffi.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
/* See path.rs. */
|
|
|
|
struct StorePath;
|
|
|
|
|
2020-01-22 22:20:01 +02:00
|
|
|
class Store;
|
2019-12-16 20:11:47 +02:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
extern "C" {
|
|
|
|
void ffi_StorePath_drop(void *);
|
|
|
|
bool ffi_StorePath_less_than(const StorePath & a, const StorePath & b);
|
|
|
|
bool ffi_StorePath_eq(const StorePath & a, const StorePath & b);
|
2020-03-23 05:43:07 +02:00
|
|
|
void ffi_StorePath_clone_to(const StorePath & _other, StorePath & _this);
|
2019-12-05 20:11:09 +02:00
|
|
|
unsigned char * ffi_StorePath_hash_data(const StorePath & p);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>
|
|
|
|
{
|
2020-02-13 17:12:16 +02:00
|
|
|
StorePath() = delete;
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
static StorePath make(std::string_view path, std::string_view storeDir);
|
|
|
|
|
|
|
|
static StorePath make(unsigned char hash[20], std::string_view name);
|
|
|
|
|
|
|
|
static StorePath fromBaseName(std::string_view baseName);
|
|
|
|
|
|
|
|
rust::String to_string() const;
|
|
|
|
|
|
|
|
bool operator < (const StorePath & other) const
|
|
|
|
{
|
|
|
|
return ffi_StorePath_less_than(*this, other);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const StorePath & other) const
|
|
|
|
{
|
|
|
|
return ffi_StorePath_eq(*this, other);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const StorePath & other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2020-03-23 05:43:07 +02:00
|
|
|
StorePath(StorePath && that) = default;
|
|
|
|
|
|
|
|
StorePath(const StorePath & that)
|
|
|
|
{
|
|
|
|
ffi_StorePath_clone_to(that, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator = (const StorePath & that)
|
|
|
|
{
|
|
|
|
(rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>::operator = (that));
|
|
|
|
ffi_StorePath_clone_to(that, *this);
|
|
|
|
}
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePath clone() const;
|
|
|
|
|
|
|
|
/* Check whether a file name ends with the extension for
|
|
|
|
derivations. */
|
|
|
|
bool isDerivation() const;
|
|
|
|
|
|
|
|
std::string_view name() const;
|
|
|
|
|
|
|
|
unsigned char * hashData() const
|
|
|
|
{
|
|
|
|
return ffi_StorePath_hash_data(*this);
|
|
|
|
}
|
2020-01-21 22:14:13 +02:00
|
|
|
|
|
|
|
static StorePath dummy;
|
2019-12-05 20:11:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::set<StorePath> StorePathSet;
|
|
|
|
typedef std::vector<StorePath> StorePaths;
|
|
|
|
|
|
|
|
StorePathSet cloneStorePathSet(const StorePathSet & paths);
|
|
|
|
StorePathSet storePathsToSet(const StorePaths & paths);
|
|
|
|
|
|
|
|
StorePathSet singleton(const StorePath & path);
|
|
|
|
|
|
|
|
/* Size of the hash part of store paths, in base-32 characters. */
|
|
|
|
const size_t storePathHashLen = 32; // i.e. 160 bits
|
|
|
|
|
|
|
|
/* Extension of derivations in the Nix store. */
|
|
|
|
const std::string drvExtension = ".drv";
|
|
|
|
|
2019-12-16 20:11:47 +02:00
|
|
|
struct StorePathWithOutputs
|
|
|
|
{
|
|
|
|
StorePath path;
|
|
|
|
std::set<std::string> outputs;
|
|
|
|
|
|
|
|
StorePathWithOutputs(const StorePath & path, const std::set<std::string> & outputs = {})
|
|
|
|
: path(path.clone()), outputs(outputs)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
StorePathWithOutputs(StorePath && path, std::set<std::string> && outputs)
|
|
|
|
: path(std::move(path)), outputs(std::move(outputs))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
StorePathWithOutputs(const StorePathWithOutputs & other)
|
|
|
|
: path(other.path.clone()), outputs(other.outputs)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
std::string to_string(const Store & store) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s);
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template<> struct hash<nix::StorePath> {
|
|
|
|
std::size_t operator()(const nix::StorePath & path) const noexcept
|
|
|
|
{
|
|
|
|
return * (std::size_t *) path.hashData();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|