getBuildLog: factor out resolving derivations

This commit is contained in:
Taeer Bar-Yam 2022-12-15 15:58:54 -05:00
parent 3b27181ee5
commit e5eb05c599
7 changed files with 16 additions and 19 deletions

View file

@ -502,14 +502,9 @@ void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSe
writeNarInfo(narInfo); writeNarInfo(narInfo);
} }
std::optional<std::string> BinaryCacheStore::getBuildLog(const StorePath & path) std::optional<std::string> BinaryCacheStore::getBuildLogExact(const StorePath & path)
{ {
auto maybePath = getBuildDerivationPath(path); auto logPath = "log/" + std::string(baseNameOf(printStorePath(path)));
if (!maybePath)
return std::nullopt;
auto drvPath = maybePath.value();
auto logPath = "log/" + std::string(baseNameOf(printStorePath(drvPath)));
debug("fetching build log from binary cache '%s/%s'", getUri(), logPath); debug("fetching build log from binary cache '%s/%s'", getUri(), logPath);

View file

@ -129,7 +129,7 @@ public:
void addSignatures(const StorePath & storePath, const StringSet & sigs) override; void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
std::optional<std::string> getBuildLog(const StorePath & path) override; std::optional<std::string> getBuildLogExact(const StorePath & path) override;
void addBuildLog(const StorePath & drvPath, std::string_view log) override; void addBuildLog(const StorePath & drvPath, std::string_view log) override;

View file

@ -1460,7 +1460,7 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual Lo
unknown, downloadSize, narSize); unknown, downloadSize, narSize);
} }
virtual std::optional<std::string> getBuildLog(const StorePath & path) override virtual std::optional<std::string> getBuildLogExact(const StorePath & path) override
{ return std::nullopt; } { return std::nullopt; }
virtual void addBuildLog(const StorePath & path, std::string_view log) override virtual void addBuildLog(const StorePath & path, std::string_view log) override

View file

@ -87,13 +87,8 @@ void LocalFSStore::narFromPath(const StorePath & path, Sink & sink)
const std::string LocalFSStore::drvsLogDir = "drvs"; const std::string LocalFSStore::drvsLogDir = "drvs";
std::optional<std::string> LocalFSStore::getBuildLog(const StorePath & path_) std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path)
{ {
auto maybePath = getBuildDerivationPath(path_);
if (!maybePath)
return std::nullopt;
auto path = maybePath.value();
auto baseName = path.to_string(); auto baseName = path.to_string();
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {

View file

@ -50,7 +50,7 @@ public:
return getRealStoreDir() + "/" + std::string(storePath, storeDir.size() + 1); return getRealStoreDir() + "/" + std::string(storePath, storeDir.size() + 1);
} }
std::optional<std::string> getBuildLog(const StorePath & path) override; std::optional<std::string> getBuildLogExact(const StorePath & path) override;
}; };

View file

@ -11,7 +11,14 @@ struct LogStore : public virtual Store
/* Return the build log of the specified store path, if available, /* Return the build log of the specified store path, if available,
or null otherwise. */ or null otherwise. */
virtual std::optional<std::string> getBuildLog(const StorePath & path) = 0; std::optional<std::string> getBuildLog(const StorePath & path) {
auto maybePath = getBuildDerivationPath(path);
if (!maybePath)
return std::nullopt;
return getBuildLogExact(maybePath.value());
}
virtual std::optional<std::string> getBuildLogExact(const StorePath & path) = 0;
virtual void addBuildLog(const StorePath & path, std::string_view log) = 0; virtual void addBuildLog(const StorePath & path, std::string_view log) = 0;

View file

@ -53,8 +53,8 @@ public:
{ return false; } { return false; }
// FIXME extend daemon protocol, move implementation to RemoteStore // FIXME extend daemon protocol, move implementation to RemoteStore
std::optional<std::string> getBuildLog(const StorePath & path) override std::optional<std::string> getBuildLogExact(const StorePath & path) override
{ unsupported("getBuildLog"); } { unsupported("getBuildLogExact"); }
private: private: