2019-12-05 20:11:09 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-06-02 22:44:58 +03:00
|
|
|
#include "content-address.hh"
|
2020-06-16 15:16:39 +03:00
|
|
|
#include "types.hh"
|
2019-12-05 20:11:09 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2020-01-22 22:20:01 +02:00
|
|
|
class Store;
|
2020-06-16 15:16:39 +03:00
|
|
|
struct Hash;
|
2019-12-16 20:11:47 +02:00
|
|
|
|
2020-06-16 15:16:39 +03:00
|
|
|
class StorePath
|
2019-12-05 20:11:09 +02:00
|
|
|
{
|
2020-06-16 15:16:39 +03:00
|
|
|
std::string baseName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* Size of the hash part of store paths, in base-32 characters. */
|
|
|
|
constexpr static size_t HashLen = 32; // i.e. 160 bits
|
|
|
|
|
2020-02-13 17:12:16 +02:00
|
|
|
StorePath() = delete;
|
|
|
|
|
2020-06-16 15:16:39 +03:00
|
|
|
StorePath(std::string_view baseName);
|
2019-12-05 20:11:09 +02:00
|
|
|
|
2020-06-16 15:16:39 +03:00
|
|
|
StorePath(const Hash & hash, std::string_view name);
|
2019-12-05 20:11:09 +02:00
|
|
|
|
2020-06-16 15:16:39 +03:00
|
|
|
std::string_view to_string() const
|
|
|
|
{
|
|
|
|
return baseName;
|
|
|
|
}
|
2019-12-05 20:11:09 +02:00
|
|
|
|
|
|
|
bool operator < (const StorePath & other) const
|
|
|
|
{
|
2020-06-16 15:16:39 +03:00
|
|
|
return baseName < other.baseName;
|
2019-12-05 20:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const StorePath & other) const
|
|
|
|
{
|
2020-06-16 15:16:39 +03:00
|
|
|
return baseName == other.baseName;
|
2019-12-05 20:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const StorePath & other) const
|
|
|
|
{
|
2020-06-16 15:16:39 +03:00
|
|
|
return baseName != other.baseName;
|
2019-12-05 20:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether a file name ends with the extension for
|
|
|
|
derivations. */
|
|
|
|
bool isDerivation() const;
|
|
|
|
|
2020-06-16 15:16:39 +03:00
|
|
|
std::string_view name() const
|
|
|
|
{
|
|
|
|
return std::string_view(baseName).substr(HashLen + 1);
|
|
|
|
}
|
2019-12-05 20:11:09 +02:00
|
|
|
|
2020-06-16 15:16:39 +03:00
|
|
|
std::string_view hashPart() const
|
2019-12-05 20:11:09 +02:00
|
|
|
{
|
2020-06-16 15:16:39 +03:00
|
|
|
return std::string_view(baseName).substr(0, HashLen);
|
2019-12-05 20:11:09 +02:00
|
|
|
}
|
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;
|
2020-06-10 12:20:52 +03:00
|
|
|
typedef std::map<string, StorePath> OutputPathMap;
|
2019-12-05 20:11:09 +02:00
|
|
|
|
2020-06-22 20:08:11 +03:00
|
|
|
typedef std::map<StorePath, std::optional<ContentAddress>> StorePathCAMap;
|
2020-06-17 22:03:05 +03:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-06-16 15:16:39 +03:00
|
|
|
return * (std::size_t *) path.to_string().data();
|
2019-12-05 20:11:09 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|