mirror of
https://github.com/NixOS/nix.git
synced 2025-11-22 18:29:36 +01:00
libutil: Add callback-based FileSystemObjectSink::createDirectory
This commit is contained in:
parent
fa380e0991
commit
09755e696a
3 changed files with 62 additions and 44 deletions
|
|
@ -200,8 +200,7 @@ static void parse(FileSystemObjectSink & sink, Source & source, const CanonPath
|
|||
}
|
||||
|
||||
else if (type == "directory") {
|
||||
sink.createDirectory(path);
|
||||
|
||||
sink.createDirectory(path, [&](FileSystemObjectSink & dirSink, const CanonPath & relDirPath) {
|
||||
std::map<Path, int, CaseInsensitiveCompare> names;
|
||||
|
||||
std::string prevName;
|
||||
|
|
@ -244,10 +243,11 @@ static void parse(FileSystemObjectSink & sink, Source & source, const CanonPath
|
|||
|
||||
expectTag("node");
|
||||
|
||||
parse(sink, source, path / name);
|
||||
parse(dirSink, source, relDirPath / name);
|
||||
|
||||
expectTag(")");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if (type == "symlink") {
|
||||
|
|
|
|||
|
|
@ -34,11 +34,12 @@ void copyRecursive(SourceAccessor & accessor, const CanonPath & from, FileSystem
|
|||
}
|
||||
|
||||
case SourceAccessor::tDirectory: {
|
||||
sink.createDirectory(to);
|
||||
sink.createDirectory(to, [&](FileSystemObjectSink & dirSink, const CanonPath & relDirPath) {
|
||||
for (auto & [name, _] : accessor.readDirectory(from)) {
|
||||
copyRecursive(accessor, from / name, sink, to / name);
|
||||
copyRecursive(accessor, from / name, dirSink, relDirPath / name);
|
||||
break;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,23 @@ struct FileSystemObjectSink
|
|||
|
||||
virtual void createDirectory(const CanonPath & path) = 0;
|
||||
|
||||
using DirectoryCreatedCallback = std::function<void(FileSystemObjectSink & dirSink, const CanonPath & dirRelPath)>;
|
||||
|
||||
/**
|
||||
* Create a directory and invoke a callback with a pair of sink + CanonPath
|
||||
* of the created subdirectory relative to dirSink.
|
||||
*
|
||||
* @note This allows for UNIX RestoreSink implementations to implement
|
||||
* *at-style accessors that always keep an open file descriptor for the
|
||||
* freshly created directory. Use this when it's important to disallow any
|
||||
* intermediate path components from being symlinks.
|
||||
*/
|
||||
virtual void createDirectory(const CanonPath & path, DirectoryCreatedCallback callback)
|
||||
{
|
||||
createDirectory(path);
|
||||
callback(*this, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function in general is no re-entrant. Only one file can be
|
||||
* written at a time.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue