Fixes:
- Identifiers starting with _ are prohibited
- Some driveby header dependency cleaning which wound up with doing some
extra fixups.
- Fucking C style casts, man. C++ made these 1000% worse by letting you
also do memory corruption with them with references.
- Remove casts to Expr * where ExprBlackHole is an incomplete type by
introducing an explicitly-cast eBlackHoleAddr as Expr *.
- An incredibly illegal cast of the text bytes of the StorePath hash
into a size_t directly. You can't DO THAT.
Replaced with actually parsing the hash so we get 100% of the bits
being entropy, then memcpying the start of the hash. If this shows
up in a profile we should just make the hash parser faster with a
lookup table or something sensible like that.
- This horrendous bit of UB which I thankfully slapped a deprecation
warning on, built, and it didn't trigger anywhere so it was dead
code and I just deleted it. But holy crap you *cannot* do that.
inline void mkString(const Symbol & s)
{
mkString(((const std::string &) s).c_str());
}
- Some wrong lints. Lots of wrong macro lints, one wrong
suspicious-sizeof lint triggered by the template being instantiated
with only pointers, but the calculation being correct for both
pointers and not-pointers.
- Exceptions in destructors strike again. I tried to catch the
exceptions that might actually happen rather than all the exceptions
imaginable. We can let the runtime hard-kill it on other exceptions
imo.
Change-Id: I71761620846cba64d66ee7ca231b20c061e69710
97 lines
1.9 KiB
C++
97 lines
1.9 KiB
C++
#pragma once
|
|
///@file
|
|
|
|
#include <string_view>
|
|
#include <string>
|
|
|
|
#include "types.hh" // IWYU pragma: keep
|
|
|
|
namespace nix {
|
|
|
|
struct Hash;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
class StorePath
|
|
{
|
|
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
|
|
|
|
constexpr static size_t MaxPathLen = 211;
|
|
|
|
StorePath() = delete;
|
|
|
|
StorePath(std::string_view baseName);
|
|
|
|
StorePath(const Hash & hash, std::string_view name);
|
|
|
|
std::string_view to_string() const
|
|
{
|
|
return baseName;
|
|
}
|
|
|
|
bool operator < (const StorePath & other) const
|
|
{
|
|
return baseName < other.baseName;
|
|
}
|
|
|
|
bool operator == (const StorePath & other) const
|
|
{
|
|
return baseName == other.baseName;
|
|
}
|
|
|
|
bool operator != (const StorePath & other) const
|
|
{
|
|
return baseName != other.baseName;
|
|
}
|
|
|
|
/**
|
|
* Check whether a file name ends with the extension for derivations.
|
|
*/
|
|
bool isDerivation() const;
|
|
|
|
std::string_view name() const
|
|
{
|
|
return std::string_view(baseName).substr(HashLen + 1);
|
|
}
|
|
|
|
std::string_view hashPart() const
|
|
{
|
|
return std::string_view(baseName).substr(0, HashLen);
|
|
}
|
|
|
|
static StorePath dummy;
|
|
|
|
static StorePath random(std::string_view name);
|
|
};
|
|
|
|
typedef std::set<StorePath> StorePathSet;
|
|
typedef std::vector<StorePath> StorePaths;
|
|
|
|
/**
|
|
* The file extension of \ref Derivation derivations when serialized
|
|
* into store objects.
|
|
*/
|
|
const std::string drvExtension = ".drv";
|
|
|
|
}
|
|
|
|
namespace std {
|
|
|
|
template<> struct hash<nix::StorePath> {
|
|
std::size_t operator()(const nix::StorePath & path) const noexcept;
|
|
};
|
|
|
|
}
|