Last active
December 3, 2019 13:03
-
-
Save edolstra/513958fc39122f1dfe09dbb5edb70cff to your computer and use it in GitHub Desktop.
FS accessors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FSAccessor { | |
virtual Stat stat(const Path & path) = 0; | |
virtual StringSet readDirectory(const Path & path) = 0; | |
virtual std::string readFile(const Path & path) = 0; | |
virtual std::string readLink(const Path & path) = 0; | |
}; | |
// Accessor to the actual filesystem. | |
struct RealFSAccessor { ... }; | |
/// Access the contents of a NAR file. | |
struct NarAccessor { ... }; | |
// Access the contents of a zipfile. | |
struct ZipFileAccessor { | |
ZipFileAccessor(const Path & zipfile); | |
}; | |
// Access a Git working directory. Disallows access to uncommitted files. | |
struct GitTreeAccessor { ... }; | |
// A filesystem that has a single file at the root. Useful to replace addTextToStore. | |
struct SingletonFileAccessor { | |
SingletonFileAccessor(const std::string & contents); | |
}; | |
// Adaptor accessor that changed the root of the filesystem. | |
// Useful for operating on a specific directory, e.g. | |
// store->addToStore(RootedAccessor(RealFSAccessor(), "/path/to/dir"))) | |
struct RootedAccessor { | |
RootedAccessor(FSAccessor & inner); | |
}; | |
// Adaptor that filters out files that don't match some predicate functor. | |
// E.g. | |
// store->addToStore(FilteringAccessor(RootedAccessor(RealFSAccessor(), "/path/to/dir")), | |
// [&](const std::string & name, const Stat & stat) { return name != "blabla"; })); | |
struct FilteringAccessor { | |
FilteringAccessor(FSAccessor & inner, FilterPred pred); | |
}; | |
// Adaptor that keeps track of all files that were accessed. | |
struct LoggingAccessor { | |
std::set<std::string> accessed; | |
LoggingAccessor(FSAccessor & inner); | |
}; | |
struct Store { | |
// Add something to the Nix store. No need for path or filter arguments, we can use adaptors for that. | |
Path addToStore(FSAccessor accessor); | |
} | |
struct EvalState { | |
/* Need to figure out how to use accessors in the evaluator. | |
All path access needs to be relative to some accessor. | |
E.g. if we're evaluating a file from inside a `GitTreeAccessor`, then | |
a path literal like `../foo/bar.nix` will need to use the same | |
`GitTreeAccessor` (and it shouldn't be able to escape). | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment