diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-04-15 15:11:34 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-04-15 15:39:48 +0200 |
commit | d1b0909894a302540f979d904dd378af1cad620c (patch) | |
tree | 691ec2d838e4449897549a537145971d9b12a3d5 /src/libstore/binary-cache-store.cc | |
parent | 99851c6f06c80fe2222c5e5fcef963804e907170 (diff) |
BinaryCacheStore::readFile(): Return a shared_ptr to a string
This allows readFile() to indicate that a file doesn't exist, and
might eliminate some large string copying.
Diffstat (limited to 'src/libstore/binary-cache-store.cc')
-rw-r--r-- | src/libstore/binary-cache-store.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 473a0b261..7c8fdfd08 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -119,7 +119,10 @@ NarInfo BinaryCacheStore::readNarInfo(const Path & storePath) } auto narInfoFile = narInfoFileFor(storePath); - auto narInfo = make_ref<NarInfo>(getFile(narInfoFile), narInfoFile); + auto data = getFile(narInfoFile); + if (!data) + throw InvalidPath(format("path ‘%s’ is not valid") % storePath); + auto narInfo = make_ref<NarInfo>(*data, narInfoFile); if (narInfo->path != storePath) throw Error(format("NAR info file for store path ‘%1%’ does not match ‘%2%’") % narInfo->path % storePath); @@ -162,25 +165,27 @@ void BinaryCacheStore::narFromPath(const Path & storePath, Sink & sink) auto nar = getFile(res.url); + if (!nar) throw Error(format("file ‘%s’ missing from binary cache") % res.url); + stats.narRead++; - stats.narReadCompressedBytes += nar.size(); + stats.narReadCompressedBytes += nar->size(); /* Decompress the NAR. FIXME: would be nice to have the remote side do this. */ if (res.compression == "none") ; else if (res.compression == "xz") - nar = decompressXZ(nar); + nar = decompressXZ(*nar); else throw Error(format("unknown NAR compression type ‘%1%’") % nar); - stats.narReadBytes += nar.size(); + stats.narReadBytes += nar->size(); - printMsg(lvlTalkative, format("exporting path ‘%1%’ (%2% bytes)") % storePath % nar.size()); + printMsg(lvlTalkative, format("exporting path ‘%1%’ (%2% bytes)") % storePath % nar->size()); - assert(nar.size() % 8 == 0); + assert(nar->size() % 8 == 0); - sink((unsigned char *) nar.c_str(), nar.size()); + sink((unsigned char *) nar->c_str(), nar->size()); } void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink) |