2016-02-24 13:48:16 +00:00
|
|
|
|
#include "archive.hh"
|
2016-02-25 16:43:19 +00:00
|
|
|
|
#include "binary-cache-store.hh"
|
2016-02-24 13:48:16 +00:00
|
|
|
|
#include "compression.hh"
|
|
|
|
|
#include "derivations.hh"
|
2016-02-25 16:43:19 +00:00
|
|
|
|
#include "fs-accessor.hh"
|
2016-02-24 13:48:16 +00:00
|
|
|
|
#include "globals.hh"
|
|
|
|
|
#include "nar-info.hh"
|
2016-02-25 16:43:19 +00:00
|
|
|
|
#include "sync.hh"
|
2016-09-02 18:24:34 +00:00
|
|
|
|
#include "remote-fs-accessor.hh"
|
2016-04-20 13:27:48 +00:00
|
|
|
|
#include "nar-info-disk-cache.hh"
|
2016-11-09 17:57:22 +00:00
|
|
|
|
#include "nar-accessor.hh"
|
2016-10-21 14:50:28 +00:00
|
|
|
|
#include "json.hh"
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
2016-09-16 16:54:14 +00:00
|
|
|
|
#include <future>
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
namespace nix {
|
|
|
|
|
|
2016-10-21 16:09:30 +00:00
|
|
|
|
/* Given requests for a path /nix/store/<x>/<y>, this accessor will
|
|
|
|
|
first download the NAR for /nix/store/<x> from the binary cache,
|
|
|
|
|
build a NAR accessor for that NAR, and use that to access <y>. */
|
|
|
|
|
struct BinaryCacheStoreAccessor : public FSAccessor
|
|
|
|
|
{
|
|
|
|
|
ref<BinaryCacheStore> store;
|
|
|
|
|
|
|
|
|
|
std::map<Path, ref<FSAccessor>> nars;
|
|
|
|
|
|
|
|
|
|
BinaryCacheStoreAccessor(ref<BinaryCacheStore> store)
|
|
|
|
|
: store(store)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<ref<FSAccessor>, Path> fetch(const Path & path_)
|
|
|
|
|
{
|
|
|
|
|
auto path = canonPath(path_);
|
|
|
|
|
|
|
|
|
|
auto storePath = store->toStorePath(path);
|
|
|
|
|
std::string restPath = std::string(path, storePath.size());
|
|
|
|
|
|
|
|
|
|
if (!store->isValidPath(storePath))
|
2016-11-25 23:37:43 +00:00
|
|
|
|
throw InvalidPath(format("path ‘%1%’ is not a valid store path") % storePath);
|
2016-10-21 16:09:30 +00:00
|
|
|
|
|
|
|
|
|
auto i = nars.find(storePath);
|
|
|
|
|
if (i != nars.end()) return {i->second, restPath};
|
|
|
|
|
|
|
|
|
|
StringSink sink;
|
|
|
|
|
store->narFromPath(storePath, sink);
|
|
|
|
|
|
|
|
|
|
auto accessor = makeNarAccessor(sink.s);
|
|
|
|
|
nars.emplace(storePath, accessor);
|
|
|
|
|
return {accessor, restPath};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Stat stat(const Path & path) override
|
|
|
|
|
{
|
|
|
|
|
auto res = fetch(path);
|
|
|
|
|
return res.first->stat(res.second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringSet readDirectory(const Path & path) override
|
|
|
|
|
{
|
|
|
|
|
auto res = fetch(path);
|
|
|
|
|
return res.first->readDirectory(res.second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string readFile(const Path & path) override
|
|
|
|
|
{
|
|
|
|
|
auto res = fetch(path);
|
|
|
|
|
return res.first->readFile(res.second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string readLink(const Path & path) override
|
|
|
|
|
{
|
|
|
|
|
auto res = fetch(path);
|
|
|
|
|
return res.first->readLink(res.second);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-01 12:49:12 +00:00
|
|
|
|
BinaryCacheStore::BinaryCacheStore(const Params & params)
|
|
|
|
|
: Store(params)
|
|
|
|
|
, compression(get(params, "compression", "xz"))
|
2016-10-21 14:50:28 +00:00
|
|
|
|
, writeNARListing(get(params, "write-nar-listing", "0") == "1")
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
2016-04-29 14:47:20 +00:00
|
|
|
|
auto secretKeyFile = get(params, "secret-key", "");
|
2016-04-29 14:28:57 +00:00
|
|
|
|
if (secretKeyFile != "")
|
2016-02-24 13:48:16 +00:00
|
|
|
|
secretKey = std::unique_ptr<SecretKey>(new SecretKey(readFile(secretKeyFile)));
|
2016-02-24 15:52:28 +00:00
|
|
|
|
|
|
|
|
|
StringSink sink;
|
|
|
|
|
sink << narVersionMagic1;
|
2016-03-04 15:49:56 +00:00
|
|
|
|
narMagic = *sink.s;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryCacheStore::init()
|
|
|
|
|
{
|
|
|
|
|
std::string cacheInfoFile = "nix-cache-info";
|
2016-05-30 11:33:05 +00:00
|
|
|
|
|
|
|
|
|
auto cacheInfo = getFile(cacheInfoFile);
|
|
|
|
|
if (!cacheInfo) {
|
2016-06-01 12:49:12 +00:00
|
|
|
|
upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n");
|
2016-05-30 11:33:05 +00:00
|
|
|
|
} else {
|
|
|
|
|
for (auto & line : tokenizeString<Strings>(*cacheInfo, "\n")) {
|
|
|
|
|
size_t colon = line.find(':');
|
|
|
|
|
if (colon == std::string::npos) continue;
|
|
|
|
|
auto name = line.substr(0, colon);
|
|
|
|
|
auto value = trim(line.substr(colon + 1, std::string::npos));
|
|
|
|
|
if (name == "StoreDir") {
|
2016-06-01 12:49:12 +00:00
|
|
|
|
if (value != storeDir)
|
2016-11-25 23:37:43 +00:00
|
|
|
|
throw Error(format("binary cache ‘%s’ is for Nix stores with prefix ‘%s’, not ‘%s’")
|
2016-06-01 12:49:12 +00:00
|
|
|
|
% getUri() % value % storeDir);
|
2016-05-30 11:33:05 +00:00
|
|
|
|
} else if (name == "WantMassQuery") {
|
|
|
|
|
wantMassQuery_ = value == "1";
|
|
|
|
|
} else if (name == "Priority") {
|
|
|
|
|
string2Int(value, priority);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:57:30 +00:00
|
|
|
|
void BinaryCacheStore::notImpl()
|
|
|
|
|
{
|
|
|
|
|
throw Error("operation not implemented for binary cache stores");
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 16:54:14 +00:00
|
|
|
|
std::shared_ptr<std::string> BinaryCacheStore::getFile(const std::string & path)
|
|
|
|
|
{
|
|
|
|
|
std::promise<std::shared_ptr<std::string>> promise;
|
|
|
|
|
getFile(path,
|
|
|
|
|
[&](std::shared_ptr<std::string> result) {
|
|
|
|
|
promise.set_value(result);
|
|
|
|
|
},
|
|
|
|
|
[&](std::exception_ptr exc) {
|
|
|
|
|
promise.set_exception(exc);
|
|
|
|
|
});
|
|
|
|
|
return promise.get_future().get();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
Path BinaryCacheStore::narInfoFileFor(const Path & storePath)
|
|
|
|
|
{
|
|
|
|
|
assertStorePath(storePath);
|
|
|
|
|
return storePathToHash(storePath) + ".narinfo";
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 14:50:28 +00:00
|
|
|
|
void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
|
2016-10-21 16:09:30 +00:00
|
|
|
|
bool repair, bool dontCheckSigs, std::shared_ptr<FSAccessor> accessor)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
2016-05-04 11:36:54 +00:00
|
|
|
|
if (!repair && isValidPath(info.path)) return;
|
|
|
|
|
|
2016-04-22 10:15:06 +00: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);
|
|
|
|
|
} catch (InvalidPath &) {
|
2016-11-25 23:37:43 +00:00
|
|
|
|
throw Error(format("cannot add ‘%s’ to the binary cache because the reference ‘%s’ is not valid")
|
2016-04-22 10:15:06 +00:00
|
|
|
|
% info.path % ref);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
auto narInfoFile = narInfoFileFor(info.path);
|
|
|
|
|
|
2016-10-21 14:50:28 +00:00
|
|
|
|
assert(nar->compare(0, narMagic.size(), narMagic) == 0);
|
2016-02-24 15:52:28 +00:00
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
auto narInfo = make_ref<NarInfo>(info);
|
|
|
|
|
|
2016-10-21 14:50:28 +00:00
|
|
|
|
narInfo->narSize = nar->size();
|
|
|
|
|
narInfo->narHash = hashString(htSHA256, *nar);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-04-20 12:12:38 +00:00
|
|
|
|
if (info.narHash && info.narHash != narInfo->narHash)
|
2016-11-25 23:37:43 +00:00
|
|
|
|
throw Error(format("refusing to copy corrupted path ‘%1%’ to binary cache") % info.path);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-10-21 16:09:30 +00:00
|
|
|
|
auto accessor_ = std::dynamic_pointer_cast<BinaryCacheStoreAccessor>(accessor);
|
|
|
|
|
|
2016-10-21 14:50:28 +00:00
|
|
|
|
/* Optionally write a JSON file containing a listing of the
|
|
|
|
|
contents of the NAR. */
|
|
|
|
|
if (writeNARListing) {
|
|
|
|
|
std::ostringstream jsonOut;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
JSONObject jsonRoot(jsonOut);
|
|
|
|
|
jsonRoot.attr("version", 1);
|
|
|
|
|
|
2016-10-21 16:09:30 +00:00
|
|
|
|
auto narAccessor = makeNarAccessor(nar);
|
|
|
|
|
|
|
|
|
|
if (accessor_)
|
|
|
|
|
accessor_->nars.emplace(info.path, narAccessor);
|
2016-10-21 14:50:28 +00:00
|
|
|
|
|
|
|
|
|
std::function<void(const Path &, JSONPlaceholder &)> recurse;
|
|
|
|
|
|
|
|
|
|
recurse = [&](const Path & path, JSONPlaceholder & res) {
|
2016-10-21 16:09:30 +00:00
|
|
|
|
auto st = narAccessor->stat(path);
|
2016-10-21 14:50:28 +00:00
|
|
|
|
|
|
|
|
|
auto obj = res.object();
|
|
|
|
|
|
|
|
|
|
switch (st.type) {
|
|
|
|
|
case FSAccessor::Type::tRegular:
|
|
|
|
|
obj.attr("type", "regular");
|
|
|
|
|
obj.attr("size", st.fileSize);
|
|
|
|
|
if (st.isExecutable)
|
|
|
|
|
obj.attr("executable", true);
|
|
|
|
|
break;
|
|
|
|
|
case FSAccessor::Type::tDirectory:
|
|
|
|
|
obj.attr("type", "directory");
|
|
|
|
|
{
|
|
|
|
|
auto res2 = obj.object("entries");
|
2016-10-21 16:09:30 +00:00
|
|
|
|
for (auto & name : narAccessor->readDirectory(path)) {
|
2016-10-21 14:50:28 +00:00
|
|
|
|
auto res3 = res2.placeholder(name);
|
|
|
|
|
recurse(path + "/" + name, res3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FSAccessor::Type::tSymlink:
|
|
|
|
|
obj.attr("type", "symlink");
|
2016-10-21 16:09:30 +00:00
|
|
|
|
obj.attr("target", narAccessor->readLink(path));
|
2016-10-21 14:50:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto res = jsonRoot.placeholder("root");
|
|
|
|
|
recurse("", res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upsertFile(storePathToHash(info.path) + ".ls.xz", *compress("xz", jsonOut.str()));
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 16:09:30 +00:00
|
|
|
|
else {
|
|
|
|
|
if (accessor_)
|
|
|
|
|
accessor_->nars.emplace(info.path, makeNarAccessor(nar));
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
/* Compress the NAR. */
|
2016-04-29 15:02:57 +00:00
|
|
|
|
narInfo->compression = compression;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
auto now1 = std::chrono::steady_clock::now();
|
2016-10-21 14:50:28 +00:00
|
|
|
|
auto narCompressed = compress(compression, *nar);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
auto now2 = std::chrono::steady_clock::now();
|
2016-04-29 15:02:57 +00:00
|
|
|
|
narInfo->fileHash = hashString(htSHA256, *narCompressed);
|
|
|
|
|
narInfo->fileSize = narCompressed->size();
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
|
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now2 - now1).count();
|
2016-11-25 23:37:43 +00:00
|
|
|
|
printMsg(lvlTalkative, format("copying path ‘%1%’ (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache")
|
2016-02-24 13:48:16 +00:00
|
|
|
|
% narInfo->path % narInfo->narSize
|
2016-10-21 14:50:28 +00:00
|
|
|
|
% ((1.0 - (double) narCompressed->size() / nar->size()) * 100.0)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
% duration);
|
|
|
|
|
|
|
|
|
|
/* Atomically write the NAR file. */
|
2016-04-29 15:43:37 +00:00
|
|
|
|
narInfo->url = "nar/" + printHash32(narInfo->fileHash) + ".nar"
|
|
|
|
|
+ (compression == "xz" ? ".xz" :
|
|
|
|
|
compression == "bzip2" ? ".bz2" :
|
|
|
|
|
"");
|
2016-05-04 11:36:54 +00:00
|
|
|
|
if (repair || !fileExists(narInfo->url)) {
|
2016-02-24 13:48:16 +00:00
|
|
|
|
stats.narWrite++;
|
2016-04-29 15:02:57 +00:00
|
|
|
|
upsertFile(narInfo->url, *narCompressed);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
} else
|
|
|
|
|
stats.narWriteAverted++;
|
|
|
|
|
|
2016-10-21 14:50:28 +00:00
|
|
|
|
stats.narWriteBytes += nar->size();
|
2016-04-29 15:02:57 +00:00
|
|
|
|
stats.narWriteCompressedBytes += narCompressed->size();
|
2016-02-24 13:48:16 +00:00
|
|
|
|
stats.narWriteCompressionTimeMs += duration;
|
|
|
|
|
|
|
|
|
|
/* Atomically write the NAR info file.*/
|
|
|
|
|
if (secretKey) narInfo->sign(*secretKey);
|
|
|
|
|
|
|
|
|
|
upsertFile(narInfoFile, narInfo->to_string());
|
|
|
|
|
|
2016-04-21 15:53:47 +00:00
|
|
|
|
auto hashPart = storePathToHash(narInfo->path);
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
|
|
|
|
auto state_(state.lock());
|
2016-04-21 15:53:47 +00:00
|
|
|
|
state_->pathInfoCache.upsert(hashPart, std::shared_ptr<NarInfo>(narInfo));
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 13:27:48 +00:00
|
|
|
|
if (diskCache)
|
2016-04-21 15:53:47 +00:00
|
|
|
|
diskCache->upsertNarInfo(getUri(), hashPart, std::shared_ptr<NarInfo>(narInfo));
|
2016-04-20 13:27:48 +00:00
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
stats.narInfoWrite++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
bool BinaryCacheStore::isValidPathUncached(const Path & storePath)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
2016-02-25 16:43:19 +00:00
|
|
|
|
// FIXME: this only checks whether a .narinfo with a matching hash
|
2016-11-25 23:37:43 +00:00
|
|
|
|
// part exists. So ‘f4kb...-foo’ matches ‘f4kb...-bar’, even
|
2016-02-25 16:43:19 +00:00
|
|
|
|
// though they shouldn't. Not easily fixed.
|
2016-02-24 13:48:16 +00:00
|
|
|
|
return fileExists(narInfoFileFor(storePath));
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 13:21:45 +00:00
|
|
|
|
void BinaryCacheStore::narFromPath(const Path & storePath, Sink & sink)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
2016-04-19 16:50:15 +00:00
|
|
|
|
auto info = queryPathInfo(storePath).cast<const NarInfo>();
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
auto nar = getFile(info->url);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
if (!nar) throw Error(format("file ‘%s’ missing from binary cache") % info->url);
|
2016-04-15 13:11:34 +00:00
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
stats.narRead++;
|
2016-04-15 13:11:34 +00:00
|
|
|
|
stats.narReadCompressedBytes += nar->size();
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
|
|
|
|
/* Decompress the NAR. FIXME: would be nice to have the remote
|
|
|
|
|
side do this. */
|
2016-04-29 15:33:22 +00:00
|
|
|
|
try {
|
2016-05-04 11:36:54 +00:00
|
|
|
|
nar = decompress(info->compression, *nar);
|
2016-04-29 15:33:22 +00:00
|
|
|
|
} catch (UnknownCompressionMethod &) {
|
2016-11-25 23:37:43 +00:00
|
|
|
|
throw Error(format("binary cache path ‘%s’ uses unknown compression method ‘%s’")
|
2016-04-29 15:33:22 +00:00
|
|
|
|
% storePath % info->compression);
|
|
|
|
|
}
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-04-15 13:11:34 +00:00
|
|
|
|
stats.narReadBytes += nar->size();
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-11-25 23:37:43 +00:00
|
|
|
|
printMsg(lvlTalkative, format("exporting path ‘%1%’ (%2% bytes)") % storePath % nar->size());
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-04-15 13:11:34 +00:00
|
|
|
|
assert(nar->size() % 8 == 0);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-04-15 13:11:34 +00:00
|
|
|
|
sink((unsigned char *) nar->c_str(), nar->size());
|
2016-03-21 16:55:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 16:54:14 +00:00
|
|
|
|
void BinaryCacheStore::queryPathInfoUncached(const Path & storePath,
|
|
|
|
|
std::function<void(std::shared_ptr<ValidPathInfo>)> success,
|
|
|
|
|
std::function<void(std::exception_ptr exc)> failure)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
2016-04-19 16:50:15 +00:00
|
|
|
|
auto narInfoFile = narInfoFileFor(storePath);
|
|
|
|
|
|
2016-09-16 16:54:14 +00:00
|
|
|
|
getFile(narInfoFile,
|
|
|
|
|
[=](std::shared_ptr<std::string> data) {
|
|
|
|
|
if (!data) return success(0);
|
2016-04-19 16:50:15 +00:00
|
|
|
|
|
2016-09-16 16:54:14 +00:00
|
|
|
|
stats.narInfoRead++;
|
2016-04-19 16:50:15 +00:00
|
|
|
|
|
2016-09-16 16:54:14 +00:00
|
|
|
|
callSuccess(success, failure, (std::shared_ptr<ValidPathInfo>)
|
|
|
|
|
std::make_shared<NarInfo>(*this, *data, narInfoFile));
|
|
|
|
|
},
|
|
|
|
|
failure);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 15:52:28 +00:00
|
|
|
|
Path BinaryCacheStore::addToStore(const string & name, const Path & srcPath,
|
|
|
|
|
bool recursive, HashType hashAlgo, PathFilter & filter, bool repair)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: some cut&paste from LocalStore::addToStore().
|
|
|
|
|
|
|
|
|
|
/* 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 13:21:45 +00:00
|
|
|
|
dumpPath(srcPath, sink, filter);
|
2016-03-04 15:49:56 +00:00
|
|
|
|
h = hashString(hashAlgo, *sink.s);
|
2016-02-24 15:52:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
auto s = readFile(srcPath);
|
|
|
|
|
dumpString(s, sink);
|
|
|
|
|
h = hashString(hashAlgo, s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValidPathInfo info;
|
2016-07-26 19:25:52 +00:00
|
|
|
|
info.path = makeFixedOutputPath(recursive, h, name);
|
2016-02-24 15:52:28 +00:00
|
|
|
|
|
2016-10-21 16:09:30 +00:00
|
|
|
|
addToStore(info, sink.s, repair, false, 0);
|
2016-02-24 15:52:28 +00:00
|
|
|
|
|
|
|
|
|
return info.path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Path BinaryCacheStore::addTextToStore(const string & name, const string & s,
|
|
|
|
|
const PathSet & references, bool repair)
|
|
|
|
|
{
|
|
|
|
|
ValidPathInfo info;
|
|
|
|
|
info.path = computeStorePathForText(name, s, references);
|
|
|
|
|
info.references = references;
|
|
|
|
|
|
|
|
|
|
if (repair || !isValidPath(info.path)) {
|
|
|
|
|
StringSink sink;
|
|
|
|
|
dumpString(s, sink);
|
2016-10-21 16:09:30 +00:00
|
|
|
|
addToStore(info, sink.s, repair, false, 0);
|
2016-02-24 15:52:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info.path;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 16:43:19 +00:00
|
|
|
|
ref<FSAccessor> BinaryCacheStore::getFSAccessor()
|
|
|
|
|
{
|
2016-09-02 18:24:34 +00:00
|
|
|
|
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()));
|
2016-02-25 16:43:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 13:07:58 +00: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;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|