Skip to content

remote-fs-accessor: return null for missing store objects - #16408

Open
domenkozar wants to merge 1 commit into
NixOS:masterfrom
cachix:remote-fs-accessor-missing-object
Open

remote-fs-accessor: return null for missing store objects#16408
domenkozar wants to merge 1 commit into
NixOS:masterfrom
cachix:remote-fs-accessor-missing-object

Conversation

@domenkozar

Copy link
Copy Markdown
Member

Motivation

Store::getFSAccessor(path) promises to return nullptr when the store object is missing. RemoteFSAccessor::accessObject instead propagated InvalidPath from queryPathInfo.

Context

Found while reviewing the profile-store work in #16395. Catch InvalidPath at the path-info lookup boundary and return nullptr, preserving other accessor errors. Includes a regression test using a local binary cache.

Comment thread src/libstore/remote-fs-accessor.cc Outdated
@xokdvium xokdvium self-assigned this Sep 1, 2026
Comment thread src/libstore-tests/local-binary-cache-store.cc Outdated
Comment thread src/libstore/remote-fs-accessor.cc Outdated
@domenkozar
domenkozar force-pushed the remote-fs-accessor-missing-object branch from 883dd71 to 1fbf496 Compare September 1, 2026 19:46
@domenkozar
domenkozar requested a review from xokdvium September 1, 2026 19:46
Comment on lines +46 to +51
/* FIXME: Correctly handle invalid names (return nullopt). */
auto [storePath, restPath] = store->toStorePath(store->storeDir + path.abs());
auto accessor = accessObject(storePath);
if (!accessor)
return std::nullopt;
return accessor->maybeLstat(restPath);

@Ericson2314 Ericson2314 Sep 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 fetch wraps

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is only needed once, but I also think that the fetch wrapper around maybeFetch is very trivial. It is just throwing if the first thing is non-null, and then returning std::pair<ref<SourceAccessor>, CanonPath> to "prove" that that check was done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't do this, then fetch version and the maybeLstat version can go out of sink --- arguably we are getting bit by that a bit already. Forcing them to stay in sync is what I am trying to accomplish here, not "DRY for DRY's sake".


void RemoteFSAccessor::anchor() {}

RemoteFSAccessor::RemoteFSAccessor(ref<Store> store, bool requireValidPath, std::optional<AbsolutePath> cacheDir)

Copy link
Copy Markdown
Contributor

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?

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh we should just share a CanonPath -> std::pair<StorePath, CanonPath> function for both, and maybe that obviates the need for my maybeFetch because that new function is the actual used-many-times nugget here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store::toStorePath can also reuse that function in its own definition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh we should just share a CanonPath -> std::pair<StorePath, CanonPath> function for both

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants