From 532d73d5d86c3d25d08a8d771a189708dac323e2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 13 Mar 2017 14:07:58 +0100 Subject: [PATCH] BinaryCacheStore: Implement getBuildLog() We assume that build logs are stored under log/, e.g. /nix/store/q7ab198v13p0f8x8wgnd75dva7d5mip6-friday-devil-0.1.1.1.drv maps to https://cache.nixos.org/log/q7ab198v13p0f8x8wgnd75dva7d5mip6-friday-devil-0.1.1.1.drv --- src/libstore/binary-cache-store.cc | 24 ++++++++++++++++++++++++ src/libstore/binary-cache-store.hh | 2 ++ src/libstore/local-fs-store.cc | 6 +++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 3e07a2aa2..120345b26 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -382,4 +382,28 @@ ref BinaryCacheStore::getFSAccessor() return make_ref(ref(shared_from_this())); } +std::shared_ptr BinaryCacheStore::getBuildLog(const Path & path) +{ + Path drvPath; + + if (isDerivation(path)) + drvPath = path; + else { + try { + auto info = queryPathInfo(path); + // FIXME: add a "Log" field to .narinfo + if (info->deriver == "") return nullptr; + drvPath = info->deriver; + } catch (InvalidPath &) { + return nullptr; + } + } + + auto logPath = "log/" + baseNameOf(drvPath); + + debug("fetching build log from binary cache ā€˜%s/%sā€™", getUri(), logPath); + + return getFile(logPath); +} + } diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh index a70d50d49..1c287056c 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/binary-cache-store.hh @@ -122,6 +122,8 @@ public: void addSignatures(const Path & storePath, const StringSet & sigs) override { notImpl(); } + std::shared_ptr getBuildLog(const Path & path) override; + }; } diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc index c5da73dba..002ee4a65 100644 --- a/src/libstore/local-fs-store.cc +++ b/src/libstore/local-fs-store.cc @@ -95,7 +95,11 @@ std::shared_ptr LocalFSStore::getBuildLog(const Path & path_) assertStorePath(path); if (!isDerivation(path)) { - path = queryPathInfo(path)->deriver; + try { + path = queryPathInfo(path)->deriver; + } catch (InvalidPath &) { + return nullptr; + } if (path == "") return nullptr; }