-
-
Notifications
You must be signed in to change notification settings - Fork 2k
remote-fs-accessor: return null for missing store objects #16408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,19 @@ namespace nix { | |
|
|
||
| void RemoteFSAccessor::anchor() {} | ||
|
|
||
| RemoteFSAccessor::RemoteFSAccessor(ref<Store> store, bool requireValidPath, std::optional<AbsolutePath> cacheDir) | ||
| RemoteFSAccessor::RemoteFSAccessor(ref<Store> store, bool, std::optional<AbsolutePath> cacheDir) | ||
| : store(store) | ||
| , narCache(cacheDir) | ||
| , requireValidPath(requireValidPath) | ||
| { | ||
| } | ||
|
|
||
| std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPath & path) | ||
| { | ||
| auto [storePath, restPath] = store->toStorePath(store->storeDir + path.abs()); | ||
| if (requireValidPath && !store->isValidPath(storePath)) | ||
| auto accessor = accessObject(storePath); | ||
| if (!accessor) | ||
| throw InvalidPath("path '%1%' is not a valid store path", store->printStorePath(storePath)); | ||
| return {ref{accessObject(storePath)}, restPath}; | ||
| return {ref{std::move(accessor)}, restPath}; | ||
| } | ||
|
|
||
| std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath & storePath) | ||
|
|
@@ -25,8 +25,12 @@ std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath & | |
| if (auto * narHash = get(narHashes, storePath.hashPart())) | ||
| return narCache.getOrInsert(*narHash, [&](Sink & sink) { store->narFromPath(storePath, sink); }); | ||
|
|
||
| // Query the path info to get the NAR hash | ||
| auto info = store->queryPathInfo(storePath); | ||
| std::shared_ptr<const ValidPathInfo> info; | ||
| try { | ||
| info = store->queryPathInfo(storePath); | ||
| } catch (InvalidPath &) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| // Cache the mapping from store path to NAR hash | ||
| narHashes.emplace(storePath.hashPart(), info->narHash); | ||
|
|
@@ -39,10 +43,12 @@ std::optional<SourceAccessor::Stat> RemoteFSAccessor::maybeLstat(const CanonPath | |
| { | ||
| if (path.isRoot()) | ||
| return Stat{.type = tDirectory}; | ||
| /* FIXME: Correctly handle invalid names (return nullopt) and don't fail on | ||
| non-existent paths. */ | ||
| auto res = fetch(path); | ||
| return res.first->maybeLstat(res.second); | ||
| /* FIXME: Correctly handle invalid names (return nullopt). */ | ||
| auto [storePath, restPath] = store->toStorePath(store->storeDir + path.abs()); | ||
| auto accessor = accessObject(storePath); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we copy the fix for that in LocalFSStore accessor? The whole storeDir + path.abs() is pretty unnecessary. No idea why it was done this way
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh we should just share a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's a bit more complicated though, because we also need to handle the case of "this CanonPath can't be a valid store path name, so return nullopt". See #16017
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had previously fixed that stuff for the local store in #16072 and sprinkled around all these FIXMEs. |
||
| if (!accessor) | ||
| return std::nullopt; | ||
| return accessor->maybeLstat(restPath); | ||
|
Comment on lines
+46
to
+51
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me think we should have a std::pair<std::shared_ptr<SourceAccessor>, CanonPath> RemoteFSAccessor::maybeFetch(const CanonPath & path);that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it's needed - the only caller would be maybeLstat which is specific enough that inlining would yield cleaner code.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is only needed once, but I also think that the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't do this, then |
||
| } | ||
|
|
||
| SourceAccessor::DirEntries RemoteFSAccessor::readDirectory(const CanonPath & path) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why leave the signature unchanged if the argument is fully unused?