Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libstore/include/nix/store/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ protected:
LRUCache<std::string, PathInfoCacheValue> pathInfoCache;
};

void invalidatePathInfoCacheFor(const StorePath & path);

SharedSync<State> state;

std::shared_ptr<NarInfoDiskCache> diskCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ struct WorkerProto::BasicClientConnection : WorkerProto::BasicConnection
const StorePathSet & paths,
SubstituteFlag maybeSubstitute);

UnkeyedValidPathInfo queryPathInfo(const StoreDirConfig & store, bool * daemonException, const StorePath & path);
std::optional<UnkeyedValidPathInfo>
queryPathInfo(const StoreDirConfig & store, bool * daemonException, const StorePath & path);

void putBuildDerivationRequest(
const StoreDirConfig & store,
Expand Down
17 changes: 10 additions & 7 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,14 @@ void RemoteStore::queryPathInfoUncached(
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
{
try {
std::shared_ptr<const ValidPathInfo> info;
{
auto info = ({
Copy link
Contributor

@xokdvium xokdvium Aug 18, 2025

Choose a reason for hiding this comment

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

Can this use an immediatelly invoked lambda instead of the GNU extension?

[&](){
  auto conn(getConnection());
  return conn->queryPathInfo(*this, &conn.daemonException, path); 
}();

This is standard C++ at least and not too much worse than the GNU extension.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, we're already using statement exprs quite a bit in Nix, and they work fine in both gcc and clang.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, yeah. But I was under the impression that is polyfill from the time before C++ had conveniences for this stuff.

Copy link
Member

@Ericson2314 Ericson2314 Aug 19, 2025

Choose a reason for hiding this comment

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

I made lots of the ({...}), and I agree that calling the lambda is better, because I think some rvalue/lvalue stuff is better defined.

(Also, because #9527 someday :))

auto conn(getConnection());
info = std::make_shared<ValidPathInfo>(
StorePath{path}, conn->queryPathInfo(*this, &conn.daemonException, path));
}
callback(std::move(info));
conn->queryPathInfo(*this, &conn.daemonException, path);
});
if (!info)
callback(nullptr);
else
callback(std::make_shared<ValidPathInfo>(StorePath{path}, *info));
} catch (...) {
callback.rethrow();
}
Expand Down Expand Up @@ -456,7 +457,9 @@ StorePath RemoteStore::addToStoreFromDump(
}
if (fsm != dumpMethod)
unsupported("RemoteStore::addToStoreFromDump doesn't support this `dumpMethod` `hashMethod` combination");
return addCAToStore(dump, name, hashMethod, hashAlgo, references, repair)->path;
auto storePath = addCAToStore(dump, name, hashMethod, hashAlgo, references, repair)->path;
invalidatePathInfoCacheFor(storePath);
return storePath;
}

void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
Expand Down
5 changes: 5 additions & 0 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ bool Store::PathInfoCacheValue::isKnownNow()
return std::chrono::steady_clock::now() < time_point + ttl;
}

void Store::invalidatePathInfoCacheFor(const StorePath & path)
{
state.lock()->pathInfoCache.erase(path.to_string());
}

std::map<std::string, std::optional<StorePath>> Store::queryStaticPartialDerivationOutputMap(const StorePath & path)
{
std::map<std::string, std::optional<StorePath>> outputs;
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/worker-protocol-connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void WorkerProto::BasicServerConnection::postHandshake(const StoreDirConfig & st
WorkerProto::write(store, *this, info);
}

UnkeyedValidPathInfo WorkerProto::BasicClientConnection::queryPathInfo(
std::optional<UnkeyedValidPathInfo> WorkerProto::BasicClientConnection::queryPathInfo(
const StoreDirConfig & store, bool * daemonException, const StorePath & path)
{
to << WorkerProto::Op::QueryPathInfo << store.printStorePath(path);
Expand All @@ -253,14 +253,14 @@ UnkeyedValidPathInfo WorkerProto::BasicClientConnection::queryPathInfo(
} catch (Error & e) {
// Ugly backwards compatibility hack.
if (e.msg().find("is not valid") != std::string::npos)
throw InvalidPath(std::move(e.info()));
return std::nullopt;
throw;
}
if (GET_PROTOCOL_MINOR(protoVersion) >= 17) {
bool valid;
from >> valid;
if (!valid)
throw InvalidPath("path '%s' is not valid", store.printStorePath(path));
return std::nullopt;
}
return WorkerProto::Serialise<UnkeyedValidPathInfo>::read(store, *this);
}
Expand Down
Loading