mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-16 23:27:17 +02:00
Cleanup
This commit is contained in:
parent
7f576f5dfe
commit
c257c82447
3 changed files with 17 additions and 6 deletions
|
@ -54,18 +54,16 @@ struct MountedInputAccessor : InputAccessor
|
||||||
std::pair<ref<InputAccessor>, CanonPath> resolve(CanonPath path)
|
std::pair<ref<InputAccessor>, CanonPath> resolve(CanonPath path)
|
||||||
{
|
{
|
||||||
// Find the nearest parent of `path` that is a mount point.
|
// Find the nearest parent of `path` that is a mount point.
|
||||||
std::vector<std::string> ss;
|
std::vector<std::string> subpath;
|
||||||
while (true) {
|
while (true) {
|
||||||
auto i = mounts.find(path);
|
auto i = mounts.find(path);
|
||||||
if (i != mounts.end()) {
|
if (i != mounts.end()) {
|
||||||
auto subpath = CanonPath::root;
|
std::reverse(subpath.begin(), subpath.end());
|
||||||
for (auto j = ss.rbegin(); j != ss.rend(); ++j)
|
return {i->second, CanonPath(subpath)};
|
||||||
subpath.push(*j);
|
|
||||||
return {i->second, std::move(subpath)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!path.isRoot());
|
assert(!path.isRoot());
|
||||||
ss.push_back(std::string(*path.baseName()));
|
subpath.push_back(std::string(*path.baseName()));
|
||||||
path.pop();
|
path.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,13 @@ CanonPath::CanonPath(std::string_view raw, const CanonPath & root)
|
||||||
: path(absPath((Path) raw, root.abs()))
|
: path(absPath((Path) raw, root.abs()))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
CanonPath::CanonPath(const std::vector<std::string> & elems)
|
||||||
|
: path("/")
|
||||||
|
{
|
||||||
|
for (auto & s : elems)
|
||||||
|
push(s);
|
||||||
|
}
|
||||||
|
|
||||||
CanonPath CanonPath::fromCwd(std::string_view path)
|
CanonPath CanonPath::fromCwd(std::string_view path)
|
||||||
{
|
{
|
||||||
return CanonPath(unchecked_t(), absPath((Path) path));
|
return CanonPath(unchecked_t(), absPath((Path) path));
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -46,6 +47,11 @@ public:
|
||||||
: path(std::move(path))
|
: path(std::move(path))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a canon path from a vector of elements.
|
||||||
|
*/
|
||||||
|
CanonPath(const std::vector<std::string> & elems);
|
||||||
|
|
||||||
static CanonPath fromCwd(std::string_view path = ".");
|
static CanonPath fromCwd(std::string_view path = ".");
|
||||||
|
|
||||||
static CanonPath root;
|
static CanonPath root;
|
||||||
|
|
Loading…
Add table
Reference in a new issue