1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-29 05:31:00 +01:00

Fix CanonPath::parent()

This also fixes flake.lock loading.
This commit is contained in:
Eelco Dolstra 2022-05-19 00:08:51 +02:00
parent c80b942c6e
commit d7d93ebdc4
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 5 additions and 3 deletions

View file

@ -16,14 +16,13 @@ CanonPath::CanonPath(std::string_view raw, const CanonPath & root)
std::optional<CanonPath> CanonPath::parent() const
{
if (isRoot()) return std::nullopt;
return CanonPath(unchecked_t(), path.substr(0, path.rfind('/')));
return CanonPath(unchecked_t(), path.substr(0, std::max((size_t) 1, path.rfind('/'))));
}
void CanonPath::pop()
{
assert(!isRoot());
auto slash = path.rfind('/');
path.resize(std::max((size_t) 1, slash));
path.resize(std::max((size_t) 1, path.rfind('/')));
}
bool CanonPath::isWithin(const CanonPath & parent) const