aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/path.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/path.hh')
-rw-r--r--src/libstore/path.hh84
1 files changed, 25 insertions, 59 deletions
diff --git a/src/libstore/path.hh b/src/libstore/path.hh
index f3ed6ca39..aaebd3ec3 100644
--- a/src/libstore/path.hh
+++ b/src/libstore/path.hh
@@ -1,73 +1,59 @@
#pragma once
-#include "rust-ffi.hh"
+#include "types.hh"
namespace nix {
-/* See path.rs. */
-struct StorePath;
-
class Store;
+struct Hash;
-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);
- void ffi_StorePath_clone_to(const StorePath & _other, StorePath & _this);
- unsigned char * ffi_StorePath_hash_data(const StorePath & p);
-}
-
-struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>
+class StorePath
{
- StorePath() = delete;
+ std::string baseName;
- static StorePath make(std::string_view path, std::string_view storeDir);
+public:
- static StorePath make(unsigned char hash[20], std::string_view name);
+ /* Size of the hash part of store paths, in base-32 characters. */
+ constexpr static size_t HashLen = 32; // i.e. 160 bits
- static StorePath fromBaseName(std::string_view baseName);
+ StorePath() = delete;
- rust::String to_string() const;
+ StorePath(std::string_view baseName);
- bool operator < (const StorePath & other) const
- {
- return ffi_StorePath_less_than(*this, other);
- }
+ StorePath(const Hash & hash, std::string_view name);
- bool operator == (const StorePath & other) const
+ std::string_view to_string() const
{
- return ffi_StorePath_eq(*this, other);
+ return baseName;
}
- bool operator != (const StorePath & other) const
+ bool operator < (const StorePath & other) const
{
- return !(*this == other);
+ return baseName < other.baseName;
}
- StorePath(StorePath && that) = default;
-
- StorePath(const StorePath & that)
+ bool operator == (const StorePath & other) const
{
- ffi_StorePath_clone_to(that, *this);
+ return baseName == other.baseName;
}
- void operator = (const StorePath & that)
+ bool operator != (const StorePath & other) const
{
- (rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>::operator = (that));
- ffi_StorePath_clone_to(that, *this);
+ return baseName != other.baseName;
}
- StorePath clone() const;
-
/* Check whether a file name ends with the extension for
derivations. */
bool isDerivation() const;
- std::string_view name() const;
+ std::string_view name() const
+ {
+ return std::string_view(baseName).substr(HashLen + 1);
+ }
- unsigned char * hashData() const
+ std::string_view hashPart() const
{
- return ffi_StorePath_hash_data(*this);
+ return std::string_view(baseName).substr(0, HashLen);
}
static StorePath dummy;
@@ -76,14 +62,6 @@ struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>
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";
@@ -97,18 +75,6 @@ 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;
};
@@ -121,7 +87,7 @@ namespace std {
template<> struct hash<nix::StorePath> {
std::size_t operator()(const nix::StorePath & path) const noexcept
{
- return * (std::size_t *) path.hashData();
+ return * (std::size_t *) path.to_string().data();
}
};