Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
path.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <string_view>
5
6
#include "
nix/util/types.hh
"
7
#include "
nix/util/json-impls.hh
"
8
#include "
nix/util/json-non-null.hh
"
9
10
namespace
nix {
11
12
struct
Hash
;
13
14
MakeError(BadStorePath,
Error
);
15
MakeError(BadStorePathName, BadStorePath);
16
23
void
checkName
(std::string_view name);
24
32
class
StorePath
33
{
34
std::string baseName;
35
36
public
:
37
41
constexpr
static
size_t
HashLen
= 32;
// i.e. 160 bits
42
48
constexpr
static
size_t
MaxNameLen
= 211;
49
53
constexpr
static
size_t
MaxBasenameLen
=
HashLen
+ 1 +
MaxNameLen
;
54
55
StorePath() =
delete
;
56
58
StorePath(std::string_view baseName);
59
61
StorePath(
const
Hash
& hash, std::string_view name);
62
63
std::string_view to_string() const noexcept
64
{
65
return
baseName;
66
}
67
68
bool
operator==(
const
StorePath
& other)
const
noexcept
=
default
;
69
auto
operator<=>(
const
StorePath
& other)
const
noexcept
=
default
;
70
74
bool
isDerivation() const noexcept;
75
79
void
requireDerivation
() const;
80
81
std::string_view name()
const
82
{
83
return
std::string_view(baseName).substr(
HashLen
+ 1);
84
}
85
86
std::string_view hashPart()
const
87
{
88
return
std::string_view(baseName).substr(0,
HashLen
);
89
}
90
91
static
const
StorePath dummy;
92
93
static
StorePath random(std::string_view name);
94
};
95
96
typedef
std::set<StorePath> StorePathSet;
97
typedef
std::vector<StorePath> StorePaths;
98
102
constexpr
std::string_view
drvExtension
=
".drv"
;
103
104
template
<>
105
struct
json_avoids_null<
StorePath
> : std::true_type
106
{};
107
108
}
// namespace nix
109
110
namespace
std {
111
112
template
<>
113
struct
hash<nix::StorePath>
114
{
115
std::size_t operator()(
const
nix::StorePath
& path)
const
noexcept
116
{
117
return
*(std::size_t *) path.to_string().data();
118
}
119
};
120
121
}
// namespace std
122
123
namespace
nix {
124
125
inline
std::size_t hash_value(
const
StorePath & path)
126
{
127
return
std::hash<StorePath>{}(path);
128
}
129
130
}
// namespace nix
131
132
JSON_IMPL(
nix::StorePath
)
nix::Error
Definition
error.hh:310
nix::StorePath
Definition
path.hh:33
nix::StorePath::MaxNameLen
static constexpr size_t MaxNameLen
Maximum length of the name, i.e. everything after <hash part>-.
Definition
path.hh:48
nix::StorePath::MaxBasenameLen
static constexpr size_t MaxBasenameLen
Maximum length of the basename admitted by the constructor from a string.
Definition
path.hh:53
nix::StorePath::HashLen
static constexpr size_t HashLen
Definition
path.hh:41
nix::StorePath::requireDerivation
void requireDerivation() const
Definition
path.cc:73
json-impls.hh
json-non-null.hh
nix::drvExtension
constexpr std::string_view drvExtension
Definition
path.hh:102
nix::checkName
void checkName(std::string_view name)
Definition
path.cc:12
nix::Hash
Definition
hash.hh:58
types.hh
libstore
include
nix
store
path.hh
Generated by
1.18.0