2019-12-05 18:11:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-30 15:12:44 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
2020-06-16 12:16:39 +00:00
|
|
|
#include "types.hh"
|
2019-12-05 18:11:09 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2020-06-16 12:16:39 +00:00
|
|
|
struct Hash;
|
2019-12-16 18:11:47 +00:00
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* \ref StorePath "Store path" is the fundamental reference type of Nix.
|
|
|
|
* A store paths refers to a Store object.
|
|
|
|
*
|
|
|
|
* See glossary.html#gloss-store-path for more information on a
|
|
|
|
* conceptual level.
|
|
|
|
*/
|
2020-06-16 12:16:39 +00:00
|
|
|
class StorePath
|
2019-12-05 18:11:09 +00:00
|
|
|
{
|
2020-06-16 12:16:39 +00:00
|
|
|
std::string baseName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Size of the hash part of store paths, in base-32 characters.
|
|
|
|
*/
|
2020-06-16 12:16:39 +00:00
|
|
|
constexpr static size_t HashLen = 32; // i.e. 160 bits
|
|
|
|
|
2023-01-19 05:26:06 +00:00
|
|
|
constexpr static size_t MaxPathLen = 211;
|
|
|
|
|
2020-02-13 15:12:16 +00:00
|
|
|
StorePath() = delete;
|
|
|
|
|
2020-06-16 12:16:39 +00:00
|
|
|
StorePath(std::string_view baseName);
|
2019-12-05 18:11:09 +00:00
|
|
|
|
2020-06-16 12:16:39 +00:00
|
|
|
StorePath(const Hash & hash, std::string_view name);
|
2019-12-05 18:11:09 +00:00
|
|
|
|
2020-06-16 12:16:39 +00:00
|
|
|
std::string_view to_string() const
|
|
|
|
{
|
|
|
|
return baseName;
|
|
|
|
}
|
2019-12-05 18:11:09 +00:00
|
|
|
|
|
|
|
bool operator < (const StorePath & other) const
|
|
|
|
{
|
2020-06-16 12:16:39 +00:00
|
|
|
return baseName < other.baseName;
|
2019-12-05 18:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const StorePath & other) const
|
|
|
|
{
|
2020-06-16 12:16:39 +00:00
|
|
|
return baseName == other.baseName;
|
2019-12-05 18:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const StorePath & other) const
|
|
|
|
{
|
2020-06-16 12:16:39 +00:00
|
|
|
return baseName != other.baseName;
|
2019-12-05 18:11:09 +00:00
|
|
|
}
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Check whether a file name ends with the extension for derivations.
|
|
|
|
*/
|
2019-12-05 18:11:09 +00:00
|
|
|
bool isDerivation() const;
|
|
|
|
|
2020-06-16 12:16:39 +00:00
|
|
|
std::string_view name() const
|
|
|
|
{
|
|
|
|
return std::string_view(baseName).substr(HashLen + 1);
|
|
|
|
}
|
2019-12-05 18:11:09 +00:00
|
|
|
|
2020-06-16 12:16:39 +00:00
|
|
|
std::string_view hashPart() const
|
2019-12-05 18:11:09 +00:00
|
|
|
{
|
2020-06-16 12:16:39 +00:00
|
|
|
return std::string_view(baseName).substr(0, HashLen);
|
2019-12-05 18:11:09 +00:00
|
|
|
}
|
2020-01-21 20:14:13 +00:00
|
|
|
|
|
|
|
static StorePath dummy;
|
2022-03-30 14:31:01 +00:00
|
|
|
|
|
|
|
static StorePath random(std::string_view name);
|
2019-12-05 18:11:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::set<StorePath> StorePathSet;
|
|
|
|
typedef std::vector<StorePath> StorePaths;
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* The file extension of \ref Derivation derivations when serialized
|
|
|
|
* into store objects.
|
|
|
|
*/
|
2019-12-05 18:11:09 +00:00
|
|
|
const std::string drvExtension = ".drv";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template<> struct hash<nix::StorePath> {
|
|
|
|
std::size_t operator()(const nix::StorePath & path) const noexcept
|
|
|
|
{
|
2020-06-16 12:16:39 +00:00
|
|
|
return * (std::size_t *) path.to_string().data();
|
2019-12-05 18:11:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|