2016-02-25 17:43:19 +01:00
|
|
|
|
#include "binary-cache-store.hh"
|
2020-05-19 16:54:39 +02:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
#include <chrono>
|
2016-09-16 18:54:14 +02:00
|
|
|
|
#include <future>
|
2020-05-19 16:54:39 +02:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
#include "archive.hh"
|
|
|
|
|
#include "compression.hh"
|
|
|
|
|
#include "derivations.hh"
|
2016-02-25 17:43:19 +01:00
|
|
|
|
#include "fs-accessor.hh"
|
2016-02-24 14:48:16 +01:00
|
|
|
|
#include "globals.hh"
|
2020-05-19 02:02:44 +02:00
|
|
|
|
#include "glog/logging.h"
|
2016-10-21 16:50:28 +02:00
|
|
|
|
#include "json.hh"
|
2016-11-09 18:57:22 +01:00
|
|
|
|
#include "nar-accessor.hh"
|
2016-04-20 15:27:48 +02:00
|
|
|
|
#include "nar-info-disk-cache.hh"
|
2016-02-24 14:48:16 +01:00
|
|
|
|
#include "nar-info.hh"
|
2016-09-02 20:24:34 +02:00
|
|
|
|
#include "remote-fs-accessor.hh"
|
2016-10-21 16:50:28 +02:00
|
|
|
|
#include "sync.hh"
|
2016-09-16 18:54:14 +02:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
namespace nix {
|
|
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
|
BinaryCacheStore::BinaryCacheStore(const Params& params) : Store(params) {
|
2016-04-29 16:28:57 +02:00
|
|
|
|
if (secretKeyFile != "") {
|
2016-02-24 14:48:16 +01:00
|
|
|
|
secretKey =
|
|
|
|
|
std::unique_ptr<SecretKey>(new SecretKey(readFile(secretKeyFile)));
|
2020-05-19 21:47:23 +02:00
|
|
|
|
}
|
2016-02-24 16:52:28 +01:00
|
|
|
|
|
|
|
|
|
StringSink sink;
|
|
|
|
|
sink << narVersionMagic1;
|
2016-03-04 16:49:56 +01:00
|
|
|
|
narMagic = *sink.s;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryCacheStore::init() {
|
|
|
|
|
std::string cacheInfoFile = "nix-cache-info";
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-05-30 13:33:05 +02:00
|
|
|
|
auto cacheInfo = getFile(cacheInfoFile);
|
|
|
|
|
if (!cacheInfo) {
|
2017-03-14 15:26:01 +01:00
|
|
|
|
upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n",
|
|
|
|
|
"text/x-nix-cache-info");
|
2016-05-30 13:33:05 +02:00
|
|
|
|
} else {
|
|
|
|
|
for (auto& line : tokenizeString<Strings>(*cacheInfo, "\n")) {
|
|
|
|
|
size_t colon = line.find(':');
|
|
|
|
|
if (colon == std::string::npos) {
|
|
|
|
|
continue;
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2016-05-30 13:33:05 +02:00
|
|
|
|
auto name = line.substr(0, colon);
|
|
|
|
|
auto value = trim(line.substr(colon + 1, std::string::npos));
|
|
|
|
|
if (name == "StoreDir") {
|
2016-06-01 14:49:12 +02:00
|
|
|
|
if (value != storeDir) {
|
2017-07-30 13:27:57 +02:00
|
|
|
|
throw Error(format("binary cache '%s' is for Nix stores with prefix "
|
|
|
|
|
"'%s', not '%s'") %
|
2016-06-01 14:49:12 +02:00
|
|
|
|
getUri() % value % storeDir);
|
2020-05-19 21:47:23 +02:00
|
|
|
|
}
|
2016-05-30 13:33:05 +02:00
|
|
|
|
} else if (name == "WantMassQuery") {
|
|
|
|
|
wantMassQuery_ = value == "1";
|
|
|
|
|
} else if (name == "Priority") {
|
|
|
|
|
string2Int(value, priority);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
}
|
2016-02-24 14:48:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-27 23:12:31 +02:00
|
|
|
|
void BinaryCacheStore::getFile(
|
|
|
|
|
const std::string& path,
|
2019-09-03 13:00:55 +02:00
|
|
|
|
Callback<std::shared_ptr<std::string>> callback) noexcept {
|
2018-03-27 23:12:31 +02:00
|
|
|
|
try {
|
|
|
|
|
callback(getFile(path));
|
|
|
|
|
} catch (...) {
|
|
|
|
|
callback.rethrow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryCacheStore::getFile(const std::string& path, Sink& sink) {
|
2016-09-16 18:54:14 +02:00
|
|
|
|
std::promise<std::shared_ptr<std::string>> promise;
|
2018-03-27 22:16:01 +02:00
|
|
|
|
getFile(path, {[&](std::future<std::shared_ptr<std::string>> result) {
|
|
|
|
|
try {
|
|
|
|
|
promise.set_value(result.get());
|
|
|
|
|
} catch (...) {
|
|
|
|
|
promise.set_exception(std::current_exception());
|
|
|
|
|
}
|
|
|
|
|
}});
|
2018-03-27 23:12:31 +02:00
|
|
|
|
auto data = promise.get_future().get();
|
|
|
|
|
sink((unsigned char*)data->data(), data->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<std::string> BinaryCacheStore::getFile(
|
|
|
|
|
const std::string& path) {
|
2019-07-10 19:46:15 +02:00
|
|
|
|
StringSink sink;
|
|
|
|
|
try {
|
|
|
|
|
getFile(path, sink);
|
|
|
|
|
} catch (NoSuchBinaryCacheFile&) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return sink.s;
|
2016-09-16 18:54:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
Path BinaryCacheStore::narInfoFileFor(const Path& storePath) {
|
|
|
|
|
assertStorePath(storePath);
|
|
|
|
|
return storePathToHash(storePath) + ".narinfo";
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 18:44:05 +01:00
|
|
|
|
void BinaryCacheStore::writeNarInfo(ref<NarInfo> narInfo) {
|
|
|
|
|
auto narInfoFile = narInfoFileFor(narInfo->path);
|
|
|
|
|
|
|
|
|
|
upsertFile(narInfoFile, narInfo->to_string(), "text/x-nix-narinfo");
|
|
|
|
|
|
|
|
|
|
auto hashPart = storePathToHash(narInfo->path);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto state_(state.lock());
|
|
|
|
|
state_->pathInfoCache.upsert(hashPart, std::shared_ptr<NarInfo>(narInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (diskCache) {
|
|
|
|
|
diskCache->upsertNarInfo(getUri(), hashPart,
|
|
|
|
|
std::shared_ptr<NarInfo>(narInfo));
|
2020-05-19 21:47:23 +02:00
|
|
|
|
}
|
2017-11-14 18:44:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 16:50:28 +02:00
|
|
|
|
void BinaryCacheStore::addToStore(const ValidPathInfo& info,
|
|
|
|
|
const ref<std::string>& nar,
|
2017-06-28 18:11:01 +02:00
|
|
|
|
RepairFlag repair, CheckSigsFlag checkSigs,
|
|
|
|
|
std::shared_ptr<FSAccessor> accessor) {
|
2016-05-04 13:36:54 +02:00
|
|
|
|
if (!repair && isValidPath(info.path)) {
|
|
|
|
|
return;
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-04-22 12:15:06 +02:00
|
|
|
|
/* Verify that all references are valid. This may do some .narinfo
|
|
|
|
|
reads, but typically they'll already be cached. */
|
|
|
|
|
for (auto& ref : info.references) {
|
|
|
|
|
try {
|
|
|
|
|
if (ref != info.path) {
|
|
|
|
|
queryPathInfo(ref);
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2016-04-22 12:15:06 +02:00
|
|
|
|
} catch (InvalidPath&) {
|
2017-07-30 13:27:57 +02:00
|
|
|
|
throw Error(format("cannot add '%s' to the binary cache because the "
|
|
|
|
|
"reference '%s' is not valid") %
|
2016-04-22 12:15:06 +02:00
|
|
|
|
info.path % ref);
|
|
|
|
|
}
|
2020-05-19 21:47:23 +02:00
|
|
|
|
}
|
2016-02-24 16:52:28 +01:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
assert(nar->compare(0, narMagic.size(), narMagic) == 0);
|
|
|
|
|
|
2016-10-21 16:50:28 +02:00
|
|
|
|
auto narInfo = make_ref<NarInfo>(info);
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2016-04-20 14:12:38 +02:00
|
|
|
|
narInfo->narSize = nar->size();
|
|
|
|
|
narInfo->narHash = hashString(htSHA256, *nar);
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2017-10-17 20:51:42 +02:00
|
|
|
|
if (info.narHash && info.narHash != narInfo->narHash) {
|
|
|
|
|
throw Error(
|
|
|
|
|
format("refusing to copy corrupted path '%1%' to binary cache") %
|
|
|
|
|
info.path);
|
2020-05-19 21:47:23 +02:00
|
|
|
|
}
|
2016-10-21 18:09:30 +02:00
|
|
|
|
|
2016-10-21 16:50:28 +02:00
|
|
|
|
auto accessor_ = std::dynamic_pointer_cast<RemoteFSAccessor>(accessor);
|
|
|
|
|
|
|
|
|
|
/* Optionally write a JSON file containing a listing of the
|
|
|
|
|
contents of the NAR. */
|
|
|
|
|
if (writeNARListing) {
|
|
|
|
|
std::ostringstream jsonOut;
|
|
|
|
|
|
2020-05-17 17:31:57 +02:00
|
|
|
|
{
|
2016-10-21 18:09:30 +02:00
|
|
|
|
JSONObject jsonRoot(jsonOut);
|
|
|
|
|
jsonRoot.attr("version", 1);
|
|
|
|
|
|
2017-12-07 00:50:46 +01:00
|
|
|
|
auto narAccessor = makeNarAccessor(nar);
|
2016-10-21 16:50:28 +02:00
|
|
|
|
|
2017-03-14 15:55:02 +01:00
|
|
|
|
if (accessor_) {
|
|
|
|
|
accessor_->addToCache(info.path, *nar, narAccessor);
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2016-10-21 16:50:28 +02:00
|
|
|
|
|
2016-10-21 18:09:30 +02:00
|
|
|
|
{
|
2017-12-07 00:50:46 +01:00
|
|
|
|
auto res = jsonRoot.placeholder("root");
|
|
|
|
|
listNar(res, narAccessor, "", true);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
}
|
2016-10-21 18:09:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 15:55:02 +01:00
|
|
|
|
upsertFile(storePathToHash(info.path) + ".ls", jsonOut.str(),
|
|
|
|
|
"application/json");
|
2020-05-17 17:31:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
2017-12-07 00:50:46 +01:00
|
|
|
|
if (accessor_) {
|
|
|
|
|
accessor_->addToCache(info.path, *nar, makeNarAccessor(nar));
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
/* Compress the NAR. */
|
2016-04-29 17:02:57 +02:00
|
|
|
|
narInfo->compression = compression;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
auto now1 = std::chrono::steady_clock::now();
|
2018-02-07 21:06:11 +01:00
|
|
|
|
auto narCompressed = compress(compression, *nar, parallelCompression);
|
2016-02-24 14:48:16 +01:00
|
|
|
|
auto now2 = std::chrono::steady_clock::now();
|
2016-04-29 17:02:57 +02:00
|
|
|
|
narInfo->fileHash = hashString(htSHA256, *narCompressed);
|
|
|
|
|
narInfo->fileSize = narCompressed->size();
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
auto duration =
|
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(now2 - now1)
|
|
|
|
|
.count();
|
2020-05-19 02:02:44 +02:00
|
|
|
|
DLOG(INFO) << "copying path '" << narInfo->path << "' (" << narInfo->narSize
|
|
|
|
|
<< " bytes, compressed "
|
|
|
|
|
<< ((1.0 - (double)narCompressed->size() / nar->size()) * 100.0)
|
|
|
|
|
<< "% in " << duration << "ms) to binary cache";
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
/* Atomically write the NAR file. */
|
2017-07-04 14:47:59 +02:00
|
|
|
|
narInfo->url = "nar/" + narInfo->fileHash.to_string(Base32, false) + ".nar" +
|
2016-04-29 17:43:37 +02:00
|
|
|
|
(compression == "xz" ? ".xz"
|
|
|
|
|
: compression == "bzip2"
|
|
|
|
|
? ".bz2"
|
2017-03-14 15:03:53 +01:00
|
|
|
|
: compression == "br" ? ".br" : "");
|
2016-05-04 13:36:54 +02:00
|
|
|
|
if (repair || !fileExists(narInfo->url)) {
|
2016-02-24 14:48:16 +01:00
|
|
|
|
stats.narWrite++;
|
2017-03-14 15:26:01 +01:00
|
|
|
|
upsertFile(narInfo->url, *narCompressed, "application/x-nix-nar");
|
2016-02-24 14:48:16 +01:00
|
|
|
|
} else {
|
|
|
|
|
stats.narWriteAverted++;
|
2020-05-19 21:47:23 +02:00
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-10-21 16:50:28 +02:00
|
|
|
|
stats.narWriteBytes += nar->size();
|
2016-04-29 17:02:57 +02:00
|
|
|
|
stats.narWriteCompressedBytes += narCompressed->size();
|
2016-02-24 14:48:16 +01:00
|
|
|
|
stats.narWriteCompressionTimeMs += duration;
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
/* Atomically write the NAR info file.*/
|
|
|
|
|
if (secretKey) {
|
|
|
|
|
narInfo->sign(*secretKey);
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2017-11-14 18:44:05 +01:00
|
|
|
|
writeNarInfo(narInfo);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
stats.narInfoWrite++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
bool BinaryCacheStore::isValidPathUncached(const Path& storePath) {
|
2016-02-25 17:43:19 +01:00
|
|
|
|
// FIXME: this only checks whether a .narinfo with a matching hash
|
2016-11-26 00:37:43 +01:00
|
|
|
|
// part exists. So ‘f4kb...-foo’ matches ‘f4kb...-bar’, even
|
2016-02-25 17:43:19 +01:00
|
|
|
|
// though they shouldn't. Not easily fixed.
|
2016-02-24 14:48:16 +01:00
|
|
|
|
return fileExists(narInfoFileFor(storePath));
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 14:21:45 +01:00
|
|
|
|
void BinaryCacheStore::narFromPath(const Path& storePath, Sink& sink) {
|
2016-04-19 18:50:15 +02:00
|
|
|
|
auto info = queryPathInfo(storePath).cast<const NarInfo>();
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2018-03-16 16:59:31 +01:00
|
|
|
|
uint64_t narSize = 0;
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2018-03-16 16:59:31 +01:00
|
|
|
|
LambdaSink wrapperSink([&](const unsigned char* data, size_t len) {
|
|
|
|
|
sink(data, len);
|
|
|
|
|
narSize += len;
|
|
|
|
|
});
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2018-08-06 15:40:29 +02:00
|
|
|
|
auto decompressor = makeDecompressionSink(info->compression, wrapperSink);
|
2016-02-24 14:48:16 +01:00
|
|
|
|
|
2018-08-06 15:40:29 +02:00
|
|
|
|
try {
|
|
|
|
|
getFile(info->url, *decompressor);
|
|
|
|
|
} catch (NoSuchBinaryCacheFile& e) {
|
|
|
|
|
throw SubstituteGone(e.what());
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-21 15:19:20 +02:00
|
|
|
|
decompressor->finish();
|
2018-08-06 15:40:29 +02:00
|
|
|
|
|
|
|
|
|
stats.narRead++;
|
|
|
|
|
// stats.narReadCompressedBytes += nar->size(); // FIXME
|
2018-03-16 16:59:31 +01:00
|
|
|
|
stats.narReadBytes += narSize;
|
2016-03-21 17:55:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 18:54:14 +02:00
|
|
|
|
void BinaryCacheStore::queryPathInfoUncached(
|
|
|
|
|
const Path& storePath,
|
2019-09-03 13:00:55 +02:00
|
|
|
|
Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept {
|
2017-08-31 15:25:58 +02:00
|
|
|
|
auto uri = getUri();
|
2020-05-19 02:02:44 +02:00
|
|
|
|
LOG(INFO) << "querying info about '" << storePath << "' on '" << uri << "'";
|
2017-08-31 15:25:58 +02:00
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
auto narInfoFile = narInfoFileFor(storePath);
|
|
|
|
|
|
2019-09-03 12:51:35 +02:00
|
|
|
|
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
|
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
|
getFile(narInfoFile, {[=](std::future<std::shared_ptr<std::string>> fut) {
|
|
|
|
|
try {
|
|
|
|
|
auto data = fut.get();
|
2018-03-27 22:16:01 +02:00
|
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
|
if (!data) {
|
|
|
|
|
return (*callbackPtr)(nullptr);
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2016-04-19 18:50:15 +02:00
|
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
|
stats.narInfoRead++;
|
2016-04-19 18:50:15 +02:00
|
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
|
(*callbackPtr)(
|
|
|
|
|
(std::shared_ptr<ValidPathInfo>)std::make_shared<NarInfo>(
|
|
|
|
|
*this, *data, narInfoFile));
|
2017-08-31 15:25:58 +02:00
|
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
|
} catch (...) {
|
|
|
|
|
callbackPtr->rethrow();
|
|
|
|
|
}
|
|
|
|
|
}});
|
2016-02-24 14:48:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 16:52:28 +01:00
|
|
|
|
Path BinaryCacheStore::addToStore(const string& name, const Path& srcPath,
|
2017-06-28 18:11:01 +02:00
|
|
|
|
bool recursive, HashType hashAlgo,
|
|
|
|
|
PathFilter& filter, RepairFlag repair) {
|
2016-02-24 16:52:28 +01:00
|
|
|
|
// FIXME: some cut&paste from LocalStore::addToStore().
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-02-24 16:52:28 +01:00
|
|
|
|
/* Read the whole path into memory. This is not a very scalable
|
|
|
|
|
method for very large paths, but `copyPath' is mainly used for
|
|
|
|
|
small files. */
|
|
|
|
|
StringSink sink;
|
|
|
|
|
Hash h;
|
|
|
|
|
if (recursive) {
|
2016-03-22 14:21:45 +01:00
|
|
|
|
dumpPath(srcPath, sink, filter);
|
2016-03-04 16:49:56 +01:00
|
|
|
|
h = hashString(hashAlgo, *sink.s);
|
2016-02-24 16:52:28 +01:00
|
|
|
|
} else {
|
|
|
|
|
auto s = readFile(srcPath);
|
|
|
|
|
dumpString(s, sink);
|
|
|
|
|
h = hashString(hashAlgo, s);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 16:52:28 +01:00
|
|
|
|
ValidPathInfo info;
|
2016-07-26 21:25:52 +02:00
|
|
|
|
info.path = makeFixedOutputPath(recursive, h, name);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2017-06-28 18:11:01 +02:00
|
|
|
|
addToStore(info, sink.s, repair, CheckSigs, nullptr);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
2016-02-24 16:52:28 +01:00
|
|
|
|
return info.path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Path BinaryCacheStore::addTextToStore(const string& name, const string& s,
|
2017-06-28 18:11:01 +02:00
|
|
|
|
const PathSet& references,
|
|
|
|
|
RepairFlag repair) {
|
2016-02-24 16:52:28 +01:00
|
|
|
|
ValidPathInfo info;
|
2016-07-26 21:25:52 +02:00
|
|
|
|
info.path = computeStorePathForText(name, s, references);
|
2016-02-24 16:52:28 +01:00
|
|
|
|
info.references = references;
|
|
|
|
|
|
|
|
|
|
if (repair || !isValidPath(info.path)) {
|
|
|
|
|
StringSink sink;
|
|
|
|
|
dumpString(s, sink);
|
2017-06-28 18:11:01 +02:00
|
|
|
|
addToStore(info, sink.s, repair, CheckSigs, nullptr);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
}
|
2016-02-24 16:52:28 +01:00
|
|
|
|
|
|
|
|
|
return info.path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ref<FSAccessor> BinaryCacheStore::getFSAccessor() {
|
|
|
|
|
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()),
|
2017-06-28 18:11:01 +02:00
|
|
|
|
localNarCache);
|
2016-02-24 16:52:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 18:44:05 +01:00
|
|
|
|
void BinaryCacheStore::addSignatures(const Path& storePath,
|
|
|
|
|
const StringSet& sigs) {
|
|
|
|
|
/* Note: this is inherently racy since there is no locking on
|
|
|
|
|
binary caches. In particular, with S3 this unreliable, even
|
|
|
|
|
when addSignatures() is called sequentially on a path, because
|
|
|
|
|
S3 might return an outdated cached version. */
|
|
|
|
|
|
|
|
|
|
auto narInfo = make_ref<NarInfo>((NarInfo&)*queryPathInfo(storePath));
|
|
|
|
|
|
|
|
|
|
narInfo->sigs.insert(sigs.begin(), sigs.end());
|
|
|
|
|
|
|
|
|
|
auto narInfoFile = narInfoFileFor(narInfo->path);
|
|
|
|
|
|
|
|
|
|
writeNarInfo(narInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 14:07:58 +01:00
|
|
|
|
std::shared_ptr<std::string> 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;
|
2020-05-19 19:55:58 +02:00
|
|
|
|
}
|
2017-03-13 14:07:58 +01:00
|
|
|
|
drvPath = info->deriver;
|
|
|
|
|
} catch (InvalidPath&) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
}
|
2017-03-13 14:07:58 +01:00
|
|
|
|
|
|
|
|
|
auto logPath = "log/" + baseNameOf(drvPath);
|
|
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
|
DLOG(INFO) << "fetching build log from binary cache '" << getUri() << "/"
|
|
|
|
|
<< logPath << "'";
|
2017-03-13 14:07:58 +01:00
|
|
|
|
|
|
|
|
|
return getFile(logPath);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 14:48:16 +01:00
|
|
|
|
} // namespace nix
|