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-02-24 13:48:16 +00:00
|
|
|
|
#include "worker-protocol.hh"
|
2016-02-25 16:43:19 +00:00
|
|
|
|
#include "nar-accessor.hh"
|
2016-04-20 13:27:48 +00:00
|
|
|
|
#include "nar-info-disk-cache.hh"
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
BinaryCacheStore::BinaryCacheStore(std::shared_ptr<Store> localStore,
|
2016-03-04 16:08:30 +00:00
|
|
|
|
const Path & secretKeyFile)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
: localStore(localStore)
|
|
|
|
|
{
|
2016-03-04 16:08:30 +00:00
|
|
|
|
if (secretKeyFile != "") {
|
2016-02-24 13:48:16 +00:00
|
|
|
|
secretKey = std::unique_ptr<SecretKey>(new SecretKey(readFile(secretKeyFile)));
|
|
|
|
|
publicKeys = std::unique_ptr<PublicKeys>(new PublicKeys);
|
2016-03-04 16:08:30 +00:00
|
|
|
|
publicKeys->emplace(secretKey->name, secretKey->toPublicKey());
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
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";
|
|
|
|
|
if (!fileExists(cacheInfoFile))
|
|
|
|
|
upsertFile(cacheInfoFile, "StoreDir: " + settings.nixStore + "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:57:30 +00:00
|
|
|
|
void BinaryCacheStore::notImpl()
|
|
|
|
|
{
|
|
|
|
|
throw Error("operation not implemented for binary cache stores");
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
Path BinaryCacheStore::narInfoFileFor(const Path & storePath)
|
|
|
|
|
{
|
|
|
|
|
assertStorePath(storePath);
|
|
|
|
|
return storePathToHash(storePath) + ".narinfo";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryCacheStore::addToCache(const ValidPathInfo & info,
|
|
|
|
|
const string & nar)
|
|
|
|
|
{
|
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 &) {
|
|
|
|
|
throw Error(format("cannot add ‘%s’ to the binary cache because the reference ‘%s’ is not valid")
|
|
|
|
|
% info.path % ref);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
auto narInfoFile = narInfoFileFor(info.path);
|
|
|
|
|
if (fileExists(narInfoFile)) return;
|
|
|
|
|
|
2016-02-24 15:52:28 +00:00
|
|
|
|
assert(nar.compare(0, narMagic.size(), narMagic) == 0);
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
auto narInfo = make_ref<NarInfo>(info);
|
|
|
|
|
|
|
|
|
|
narInfo->narSize = nar.size();
|
|
|
|
|
narInfo->narHash = hashString(htSHA256, nar);
|
|
|
|
|
|
2016-04-20 12:12:38 +00:00
|
|
|
|
if (info.narHash && info.narHash != narInfo->narHash)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
throw Error(format("refusing to copy corrupted path ‘%1%’ to binary cache") % info.path);
|
|
|
|
|
|
|
|
|
|
/* Compress the NAR. */
|
|
|
|
|
narInfo->compression = "xz";
|
|
|
|
|
auto now1 = std::chrono::steady_clock::now();
|
|
|
|
|
string narXz = compressXZ(nar);
|
|
|
|
|
auto now2 = std::chrono::steady_clock::now();
|
|
|
|
|
narInfo->fileHash = hashString(htSHA256, narXz);
|
|
|
|
|
narInfo->fileSize = narXz.size();
|
|
|
|
|
|
|
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now2 - now1).count();
|
|
|
|
|
printMsg(lvlTalkative, format("copying path ‘%1%’ (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache")
|
|
|
|
|
% narInfo->path % narInfo->narSize
|
|
|
|
|
% ((1.0 - (double) narXz.size() / nar.size()) * 100.0)
|
|
|
|
|
% duration);
|
|
|
|
|
|
|
|
|
|
/* Atomically write the NAR file. */
|
|
|
|
|
narInfo->url = "nar/" + printHash32(narInfo->fileHash) + ".nar.xz";
|
|
|
|
|
if (!fileExists(narInfo->url)) {
|
|
|
|
|
stats.narWrite++;
|
|
|
|
|
upsertFile(narInfo->url, narXz);
|
|
|
|
|
} else
|
|
|
|
|
stats.narWriteAverted++;
|
|
|
|
|
|
|
|
|
|
stats.narWriteBytes += nar.size();
|
|
|
|
|
stats.narWriteCompressedBytes += narXz.size();
|
|
|
|
|
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
|
|
|
|
|
// part exists. So ‘f4kb...-foo’ matches ‘f4kb...-bar’, even
|
|
|
|
|
// 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-04-19 16:50:15 +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-19 16:50:15 +00:00
|
|
|
|
if (info->compression == "none")
|
2016-02-24 13:48:16 +00:00
|
|
|
|
;
|
2016-04-19 16:50:15 +00:00
|
|
|
|
else if (info->compression == "xz")
|
2016-04-15 13:11:34 +00:00
|
|
|
|
nar = decompressXZ(*nar);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
else
|
2016-04-28 12:12:10 +00:00
|
|
|
|
throw Error(format("unknown NAR compression type ‘%1%’") % 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-04-15 13:11:34 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink)
|
|
|
|
|
{
|
|
|
|
|
assert(!sign);
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
auto res = queryPathInfo(storePath);
|
2016-03-21 16:55:57 +00:00
|
|
|
|
|
2016-03-22 13:21:45 +00:00
|
|
|
|
narFromPath(storePath, sink);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: check integrity of NAR.
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
sink << exportMagic << storePath << res->references << res->deriver << 0;
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 14:20:10 +00:00
|
|
|
|
Paths BinaryCacheStore::importPaths(bool requireSignature, Source & source,
|
|
|
|
|
std::shared_ptr<FSAccessor> accessor)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
|
|
|
|
assert(!requireSignature);
|
|
|
|
|
Paths res;
|
|
|
|
|
while (true) {
|
|
|
|
|
unsigned long long n = readLongLong(source);
|
|
|
|
|
if (n == 0) break;
|
|
|
|
|
if (n != 1) throw Error("input doesn't look like something created by ‘nix-store --export’");
|
2016-02-26 14:20:10 +00:00
|
|
|
|
res.push_back(importPath(source, accessor));
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct TeeSource : Source
|
|
|
|
|
{
|
|
|
|
|
Source & readSource;
|
2016-03-04 15:49:56 +00:00
|
|
|
|
ref<std::string> data;
|
|
|
|
|
TeeSource(Source & readSource)
|
|
|
|
|
: readSource(readSource)
|
|
|
|
|
, data(make_ref<std::string>())
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
size_t read(unsigned char * data, size_t len)
|
|
|
|
|
{
|
|
|
|
|
size_t n = readSource.read(data, len);
|
2016-03-04 15:49:56 +00:00
|
|
|
|
this->data->append((char *) data, n);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct NopSink : ParseSink
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
std::shared_ptr<ValidPathInfo> BinaryCacheStore::queryPathInfoUncached(const Path & storePath)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
{
|
2016-04-19 16:50:15 +00:00
|
|
|
|
auto narInfoFile = narInfoFileFor(storePath);
|
|
|
|
|
auto data = getFile(narInfoFile);
|
|
|
|
|
if (!data) return 0;
|
|
|
|
|
|
|
|
|
|
auto narInfo = make_ref<NarInfo>(*data, narInfoFile);
|
|
|
|
|
|
|
|
|
|
stats.narInfoRead++;
|
|
|
|
|
|
|
|
|
|
if (publicKeys) {
|
|
|
|
|
if (!narInfo->checkSignatures(*publicKeys))
|
|
|
|
|
throw Error(format("no good signature on NAR info file ‘%1%’") % narInfoFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::shared_ptr<NarInfo>(narInfo);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryCacheStore::querySubstitutablePathInfos(const PathSet & paths,
|
|
|
|
|
SubstitutablePathInfos & infos)
|
|
|
|
|
{
|
|
|
|
|
PathSet left;
|
|
|
|
|
|
|
|
|
|
if (!localStore) return;
|
|
|
|
|
|
|
|
|
|
for (auto & storePath : paths) {
|
2016-04-19 16:50:15 +00:00
|
|
|
|
try {
|
|
|
|
|
auto info = localStore->queryPathInfo(storePath);
|
|
|
|
|
SubstitutablePathInfo sub;
|
|
|
|
|
sub.references = info->references;
|
|
|
|
|
sub.downloadSize = 0;
|
|
|
|
|
sub.narSize = info->narSize;
|
|
|
|
|
infos.emplace(storePath, sub);
|
|
|
|
|
} catch (InvalidPath &) {
|
2016-02-24 13:48:16 +00:00
|
|
|
|
left.insert(storePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings.useSubstitutes)
|
|
|
|
|
localStore->querySubstitutablePathInfos(left, infos);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
info.path = makeFixedOutputPath(recursive, hashAlgo, h, name);
|
|
|
|
|
|
|
|
|
|
if (repair || !isValidPath(info.path))
|
2016-03-04 15:49:56 +00:00
|
|
|
|
addToCache(info, *sink.s);
|
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-03-04 15:49:56 +00:00
|
|
|
|
addToCache(info, *sink.s);
|
2016-02-24 15:52:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info.path;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
void BinaryCacheStore::buildPaths(const PathSet & paths, BuildMode buildMode)
|
|
|
|
|
{
|
|
|
|
|
for (auto & storePath : paths) {
|
|
|
|
|
assert(!isDerivation(storePath));
|
|
|
|
|
|
|
|
|
|
if (isValidPath(storePath)) continue;
|
|
|
|
|
|
|
|
|
|
if (!localStore)
|
|
|
|
|
throw Error(format("don't know how to realise path ‘%1%’ in a binary cache") % storePath);
|
|
|
|
|
|
|
|
|
|
localStore->addTempRoot(storePath);
|
|
|
|
|
|
|
|
|
|
if (!localStore->isValidPath(storePath))
|
|
|
|
|
localStore->ensurePath(storePath);
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
auto info = localStore->queryPathInfo(storePath);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
for (auto & ref : info->references)
|
2016-02-24 13:48:16 +00:00
|
|
|
|
if (ref != storePath)
|
|
|
|
|
ensurePath(ref);
|
|
|
|
|
|
|
|
|
|
StringSink sink;
|
|
|
|
|
dumpPath(storePath, sink);
|
|
|
|
|
|
2016-04-19 16:50:15 +00:00
|
|
|
|
addToCache(*info, *sink.s);
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryCacheStore::ensurePath(const Path & path)
|
|
|
|
|
{
|
|
|
|
|
buildPaths({path});
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 16:43:19 +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 = toStorePath(path);
|
|
|
|
|
std::string restPath = std::string(path, storePath.size());
|
|
|
|
|
|
|
|
|
|
if (!store->isValidPath(storePath))
|
|
|
|
|
throw Error(format("path ‘%1%’ is not a valid store path") % storePath);
|
|
|
|
|
|
|
|
|
|
auto i = nars.find(storePath);
|
|
|
|
|
if (i != nars.end()) return {i->second, restPath};
|
|
|
|
|
|
|
|
|
|
StringSink sink;
|
|
|
|
|
store->exportPath(storePath, false, sink);
|
|
|
|
|
|
2016-03-04 15:49:56 +00:00
|
|
|
|
auto accessor = makeNarAccessor(sink.s);
|
2016-02-25 16:43:19 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ref<FSAccessor> BinaryCacheStore::getFSAccessor()
|
|
|
|
|
{
|
|
|
|
|
return make_ref<BinaryCacheStoreAccessor>(ref<BinaryCacheStore>(
|
|
|
|
|
std::dynamic_pointer_cast<BinaryCacheStore>(shared_from_this())));
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 14:20:10 +00:00
|
|
|
|
Path BinaryCacheStore::importPath(Source & source, std::shared_ptr<FSAccessor> accessor)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: some cut&paste of LocalStore::importPath(). */
|
|
|
|
|
|
|
|
|
|
/* Extract the NAR from the source. */
|
|
|
|
|
TeeSource tee(source);
|
|
|
|
|
NopSink sink;
|
|
|
|
|
parseDump(sink, tee);
|
|
|
|
|
|
|
|
|
|
uint32_t magic = readInt(source);
|
|
|
|
|
if (magic != exportMagic)
|
|
|
|
|
throw Error("Nix archive cannot be imported; wrong format");
|
|
|
|
|
|
|
|
|
|
ValidPathInfo info;
|
|
|
|
|
info.path = readStorePath(source);
|
|
|
|
|
|
|
|
|
|
info.references = readStorePaths<PathSet>(source);
|
|
|
|
|
|
|
|
|
|
readString(source); // deriver, don't care
|
|
|
|
|
|
|
|
|
|
bool haveSignature = readInt(source) == 1;
|
|
|
|
|
assert(!haveSignature);
|
|
|
|
|
|
2016-03-04 15:49:56 +00:00
|
|
|
|
addToCache(info, *tee.data);
|
2016-02-26 14:20:10 +00:00
|
|
|
|
|
|
|
|
|
auto accessor_ = std::dynamic_pointer_cast<BinaryCacheStoreAccessor>(accessor);
|
|
|
|
|
if (accessor_)
|
2016-03-04 15:49:56 +00:00
|
|
|
|
accessor_->nars.emplace(info.path, makeNarAccessor(tee.data));
|
2016-02-26 14:20:10 +00:00
|
|
|
|
|
|
|
|
|
return info.path;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 13:48:16 +00:00
|
|
|
|
}
|