mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-11 00:36:20 +02:00
Fix CanonPath::parent()
This also fixes flake.lock loading.
This commit is contained in:
parent
c80b942c6e
commit
d7d93ebdc4
2 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace nix {
|
|||
ASSERT_EQ(p.rel(), "");
|
||||
ASSERT_EQ(p.baseName(), std::nullopt);
|
||||
ASSERT_EQ(p.dirOf(), std::nullopt);
|
||||
ASSERT_FALSE(p.parent());
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -19,6 +20,7 @@ namespace nix {
|
|||
ASSERT_EQ(p.rel(), "foo");
|
||||
ASSERT_EQ(*p.baseName(), "foo");
|
||||
ASSERT_EQ(*p.dirOf(), ""); // FIXME: do we want this?
|
||||
ASSERT_EQ(p.parent()->abs(), "/");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -27,6 +29,7 @@ namespace nix {
|
|||
ASSERT_EQ(p.rel(), "foo/bar");
|
||||
ASSERT_EQ(*p.baseName(), "bar");
|
||||
ASSERT_EQ(*p.dirOf(), "/foo");
|
||||
ASSERT_EQ(p.parent()->abs(), "/foo");
|
||||
}
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue