aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/binary-cache-store.cc24
-rw-r--r--src/libstore/binary-cache-store.hh9
-rw-r--r--src/libstore/build/derivation-goal.cc2
-rw-r--r--src/libstore/build/local-derivation-goal.cc6
-rw-r--r--src/libstore/daemon.cc14
-rw-r--r--src/libstore/export-import.cc6
-rw-r--r--src/libstore/filetransfer.cc20
-rw-r--r--src/libstore/filetransfer.hh8
-rw-r--r--src/libstore/http-binary-cache-store.cc8
-rw-r--r--src/libstore/legacy-ssh-store.cc2
-rw-r--r--src/libstore/local-fs-store.cc16
-rw-r--r--src/libstore/local-fs-store.hh3
-rw-r--r--src/libstore/local-store.cc4
-rw-r--r--src/libstore/nar-accessor.cc8
-rw-r--r--src/libstore/nar-accessor.hh2
-rw-r--r--src/libstore/remote-fs-accessor.cc30
-rw-r--r--src/libstore/remote-fs-accessor.hh3
-rw-r--r--src/libstore/remote-store.cc2
-rw-r--r--src/libstore/s3-binary-cache-store.cc2
-rw-r--r--src/libstore/s3.hh4
-rw-r--r--src/libstore/store-api.hh4
21 files changed, 90 insertions, 87 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index 13c086a46..8aec632e8 100644
--- a/src/libstore/binary-cache-store.cc
+++ b/src/libstore/binary-cache-store.cc
@@ -31,7 +31,7 @@ BinaryCacheStore::BinaryCacheStore(const Params & params)
StringSink sink;
sink << narVersionMagic1;
- narMagic = *sink.s;
+ narMagic = sink.s;
}
void BinaryCacheStore::init()
@@ -68,7 +68,7 @@ void BinaryCacheStore::upsertFile(const std::string & path,
}
void BinaryCacheStore::getFile(const std::string & path,
- Callback<std::shared_ptr<std::string>> callback) noexcept
+ Callback<std::optional<std::string>> callback) noexcept
{
try {
callback(getFile(path));
@@ -77,9 +77,9 @@ void BinaryCacheStore::getFile(const std::string & path,
void BinaryCacheStore::getFile(const std::string & path, Sink & sink)
{
- std::promise<std::shared_ptr<std::string>> promise;
+ std::promise<std::optional<std::string>> promise;
getFile(path,
- {[&](std::future<std::shared_ptr<std::string>> result) {
+ {[&](std::future<std::optional<std::string>> result) {
try {
promise.set_value(result.get());
} catch (...) {
@@ -89,15 +89,15 @@ void BinaryCacheStore::getFile(const std::string & path, Sink & sink)
sink(*promise.get_future().get());
}
-std::shared_ptr<std::string> BinaryCacheStore::getFile(const std::string & path)
+std::optional<std::string> BinaryCacheStore::getFile(const std::string & path)
{
StringSink sink;
try {
getFile(path, sink);
} catch (NoSuchBinaryCacheFile &) {
- return nullptr;
+ return std::nullopt;
}
- return sink.s;
+ return std::move(sink.s);
}
std::string BinaryCacheStore::narInfoFileFor(const StorePath & storePath)
@@ -367,7 +367,7 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
getFile(narInfoFile,
- {[=](std::future<std::shared_ptr<std::string>> fut) {
+ {[=](std::future<std::optional<std::string>> fut) {
try {
auto data = fut.get();
@@ -429,7 +429,7 @@ StorePath BinaryCacheStore::addTextToStore(const string & name, const string & s
StringSink sink;
dumpString(s, sink);
- auto source = StringSource { *sink.s };
+ StringSource source(sink.s);
return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info { path, nar.first };
info.narSize = nar.second;
@@ -446,8 +446,8 @@ void BinaryCacheStore::queryRealisationUncached(const DrvOutput & id,
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
- Callback<std::shared_ptr<std::string>> newCallback = {
- [=](std::future<std::shared_ptr<std::string>> fut) {
+ Callback<std::optional<std::string>> newCallback = {
+ [=](std::future<std::optional<std::string>> fut) {
try {
auto data = fut.get();
if (!data) return (*callbackPtr)(nullptr);
@@ -490,7 +490,7 @@ void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSe
writeNarInfo(narInfo);
}
-std::shared_ptr<std::string> BinaryCacheStore::getBuildLog(const StorePath & path)
+std::optional<std::string> BinaryCacheStore::getBuildLog(const StorePath & path)
{
auto drvPath = path;
diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh
index 9815af591..46ff67c77 100644
--- a/src/libstore/binary-cache-store.hh
+++ b/src/libstore/binary-cache-store.hh
@@ -62,10 +62,11 @@ public:
/* Fetch the specified file and call the specified callback with
the result. A subclass may implement this asynchronously. */
- virtual void getFile(const std::string & path,
- Callback<std::shared_ptr<std::string>> callback) noexcept;
+ virtual void getFile(
+ const std::string & path,
+ Callback<std::optional<std::string>> callback) noexcept;
- std::shared_ptr<std::string> getFile(const std::string & path);
+ std::optional<std::string> getFile(const std::string & path);
public:
@@ -117,7 +118,7 @@ public:
void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
- std::shared_ptr<std::string> getBuildLog(const StorePath & path) override;
+ std::optional<std::string> getBuildLog(const StorePath & path) override;
};
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc
index d34e53fe8..151217b8b 100644
--- a/src/libstore/build/derivation-goal.cc
+++ b/src/libstore/build/derivation-goal.cc
@@ -278,7 +278,7 @@ void DerivationGoal::outputsSubstitutionTried()
if (nrFailed > 0 && nrFailed > nrNoSubstituters + nrIncompleteClosure && !settings.tryFallback) {
done(BuildResult::TransientFailure,
- fmt("some substitutes for the outputs of derivation '%s' failed (usually happens due to networking issues); try '--fallback' to build derivation from source ",
+ Error("some substitutes for the outputs of derivation '%s' failed (usually happens due to networking issues); try '--fallback' to build derivation from source ",
worker.store.printStorePath(drvPath)));
return;
}
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index e4d2add73..0d0afea2d 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -2226,8 +2226,8 @@ void LocalDerivationGoal::registerOutputs()
StringSink sink;
dumpPath(actualPath, sink);
deletePath(actualPath);
- sink.s = make_ref<std::string>(rewriteStrings(*sink.s, outputRewrites));
- StringSource source(*sink.s);
+ sink.s = rewriteStrings(sink.s, outputRewrites);
+ StringSource source(sink.s);
restorePath(actualPath, source);
}
};
@@ -2295,7 +2295,7 @@ void LocalDerivationGoal::registerOutputs()
StringSink sink;
dumpPath(actualPath, sink);
RewritingSink rsink2(oldHashPart, std::string(finalPath.hashPart()), nextSink);
- rsink2(*sink.s);
+ rsink2(sink.s);
rsink2.flush();
});
Path tmpPath = actualPath + ".tmp";
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index 59325da79..5b817c587 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -69,7 +69,7 @@ struct TunnelLogger : public Logger
StringSink buf;
buf << STDERR_NEXT << (fs.s + "\n");
- enqueueMsg(*buf.s);
+ enqueueMsg(buf.s);
}
void logEI(const ErrorInfo & ei) override
@@ -81,7 +81,7 @@ struct TunnelLogger : public Logger
StringSink buf;
buf << STDERR_NEXT << oss.str();
- enqueueMsg(*buf.s);
+ enqueueMsg(buf.s);
}
/* startWork() means that we're starting an operation for which we
@@ -129,7 +129,7 @@ struct TunnelLogger : public Logger
StringSink buf;
buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent;
- enqueueMsg(*buf.s);
+ enqueueMsg(buf.s);
}
void stopActivity(ActivityId act) override
@@ -137,7 +137,7 @@ struct TunnelLogger : public Logger
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf;
buf << STDERR_STOP_ACTIVITY << act;
- enqueueMsg(*buf.s);
+ enqueueMsg(buf.s);
}
void result(ActivityId act, ResultType type, const Fields & fields) override
@@ -145,7 +145,7 @@ struct TunnelLogger : public Logger
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
StringSink buf;
buf << STDERR_RESULT << act << type << fields;
- enqueueMsg(*buf.s);
+ enqueueMsg(buf.s);
}
};
@@ -852,14 +852,14 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
else {
std::unique_ptr<Source> source;
+ StringSink saved;
if (GET_PROTOCOL_MINOR(clientVersion) >= 21)
source = std::make_unique<TunnelSource>(from, to);
else {
- StringSink saved;
TeeSource tee { from, saved };
ParseSink ether;
parseDump(ether, tee);
- source = std::make_unique<StringSource>(std::move(*saved.s));
+ source = std::make_unique<StringSource>(saved.s);
}
logger->startWork();
diff --git a/src/libstore/export-import.cc b/src/libstore/export-import.cc
index 02c839520..9875da909 100644
--- a/src/libstore/export-import.cc
+++ b/src/libstore/export-import.cc
@@ -75,20 +75,20 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
auto references = worker_proto::read(*this, source, Phantom<StorePathSet> {});
auto deriver = readString(source);
- auto narHash = hashString(htSHA256, *saved.s);
+ auto narHash = hashString(htSHA256, saved.s);
ValidPathInfo info { path, narHash };
if (deriver != "")
info.deriver = parseStorePath(deriver);
info.references = references;
- info.narSize = saved.s->size();
+ info.narSize = saved.s.size();
// Ignore optional legacy signature.
if (readInt(source) == 1)
readString(source);
// Can't use underlying source, which would have been exhausted
- auto source = StringSource { *saved.s };
+ auto source = StringSource(saved.s);
addToStore(info, source, NoRepair, checkSigs);
res.push_back(info.path);
diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc
index 17980ab22..6b62311cf 100644
--- a/src/libstore/filetransfer.cc
+++ b/src/libstore/filetransfer.cc
@@ -106,7 +106,7 @@ struct curlFileTransfer : public FileTransfer
this->request.dataCallback(data);
}
} else
- this->result.data->append(data);
+ this->result.data.append(data);
})
{
if (!request.expectedETag.empty())
@@ -195,7 +195,7 @@ struct curlFileTransfer : public FileTransfer
std::smatch match;
if (std::regex_match(line, match, statusLine)) {
result.etag = "";
- result.data = std::make_shared<std::string>();
+ result.data.clear();
result.bodySize = 0;
statusMsg = trim(match[1]);
acceptRanges = false;
@@ -340,7 +340,7 @@ struct curlFileTransfer : public FileTransfer
if (writtenToSink)
curl_easy_setopt(req, CURLOPT_RESUME_FROM_LARGE, writtenToSink);
- result.data = std::make_shared<std::string>();
+ result.data.clear();
result.bodySize = 0;
}
@@ -434,21 +434,21 @@ struct curlFileTransfer : public FileTransfer
attempt++;
- std::shared_ptr<std::string> response;
+ std::optional<std::string> response;
if (errorSink)
- response = errorSink->s;
+ response = std::move(errorSink->s);
auto exc =
code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted
- ? FileTransferError(Interrupted, response, "%s of '%s' was interrupted", request.verb(), request.uri)
+ ? FileTransferError(Interrupted, std::move(response), "%s of '%s' was interrupted", request.verb(), request.uri)
: httpStatus != 0
? FileTransferError(err,
- response,
+ std::move(response),
fmt("unable to %s '%s': HTTP error %d ('%s')",
request.verb(), request.uri, httpStatus, statusMsg)
+ (code == CURLE_OK ? "" : fmt(" (curl error: %s)", curl_easy_strerror(code)))
)
: FileTransferError(err,
- response,
+ std::move(response),
fmt("unable to %s '%s': %s (%d)",
request.verb(), request.uri, curl_easy_strerror(code), code));
@@ -705,7 +705,7 @@ struct curlFileTransfer : public FileTransfer
FileTransferResult res;
if (!s3Res.data)
throw FileTransferError(NotFound, nullptr, "S3 object '%s' does not exist", request.uri);
- res.data = s3Res.data;
+ res.data = std::move(*s3Res.data);
callback(std::move(res));
#else
throw nix::Error("cannot download '%s' because Nix is not built with S3 support", request.uri);
@@ -859,7 +859,7 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink)
}
template<typename... Args>
-FileTransferError::FileTransferError(FileTransfer::Error error, std::shared_ptr<string> response, const Args & ... args)
+FileTransferError::FileTransferError(FileTransfer::Error error, std::optional<std::string> response, const Args & ... args)
: Error(args...), error(error), response(response)
{
const auto hf = hintfmt(args...);
diff --git a/src/libstore/filetransfer.hh b/src/libstore/filetransfer.hh
index 45d9ccf89..3e61b23b1 100644
--- a/src/libstore/filetransfer.hh
+++ b/src/libstore/filetransfer.hh
@@ -59,7 +59,7 @@ struct FileTransferRequest
unsigned int baseRetryTimeMs = 250;
ActivityId parentAct;
bool decompress = true;
- std::shared_ptr<std::string> data;
+ std::optional<std::string> data;
std::string mimeType;
std::function<void(std::string_view data)> dataCallback;
@@ -77,7 +77,7 @@ struct FileTransferResult
bool cached = false;
std::string etag;
std::string effectiveUri;
- std::shared_ptr<std::string> data;
+ std::string data;
uint64_t bodySize = 0;
};
@@ -119,10 +119,10 @@ class FileTransferError : public Error
{
public:
FileTransfer::Error error;
- std::shared_ptr<string> response; // intentionally optional
+ std::optional<string> response; // intentionally optional
template<typename... Args>
- FileTransferError(FileTransfer::Error error, std::shared_ptr<string> response, const Args & ... args);
+ FileTransferError(FileTransfer::Error error, std::optional<string> response, const Args & ... args);
virtual const char* sname() const override { return "FileTransferError"; }
};
diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc
index 605ec4b28..3cb5efdbf 100644
--- a/src/libstore/http-binary-cache-store.cc
+++ b/src/libstore/http-binary-cache-store.cc
@@ -126,7 +126,7 @@ protected:
const std::string & mimeType) override
{
auto req = makeRequest(path);
- req.data = std::make_shared<string>(StreamToSourceAdapter(istream).drain());
+ req.data = StreamToSourceAdapter(istream).drain();
req.mimeType = mimeType;
try {
getFileTransfer()->upload(req);
@@ -159,7 +159,7 @@ protected:
}
void getFile(const std::string & path,
- Callback<std::shared_ptr<std::string>> callback) noexcept override
+ Callback<std::optional<std::string>> callback) noexcept override
{
checkEnabled();
@@ -170,10 +170,10 @@ protected:
getFileTransfer()->enqueueFileTransfer(request,
{[callbackPtr, this](std::future<FileTransferResult> result) {
try {
- (*callbackPtr)(result.get().data);
+ (*callbackPtr)(std::move(result.get().data));
} catch (FileTransferError & e) {
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden)
- return (*callbackPtr)(std::shared_ptr<std::string>());
+ return (*callbackPtr)({});
maybeDisable();
callbackPtr->rethrow();
} catch (...) {
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 4861d185e..f8b2662af 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -94,7 +94,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
conn->sshConn->in.close();
auto msg = conn->from.drain();
throw Error("'nix-store --serve' protocol mismatch from '%s', got '%s'",
- host, chomp(*saved.s + msg));
+ host, chomp(saved.s + msg));
}
conn->remoteVersion = readInt(conn->from);
if (GET_PROTOCOL_MAJOR(conn->remoteVersion) != 0x200)
diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc
index 6de13c73a..c933251db 100644
--- a/src/libstore/local-fs-store.cc
+++ b/src/libstore/local-fs-store.cc
@@ -87,34 +87,32 @@ void LocalFSStore::narFromPath(const StorePath & path, Sink & sink)
const string LocalFSStore::drvsLogDir = "drvs";
-
-
-std::shared_ptr<std::string> LocalFSStore::getBuildLog(const StorePath & path_)
+std::optional<std::string> LocalFSStore::getBuildLog(const StorePath & path_)
{
auto path = path_;
if (!path.isDerivation()) {
try {
auto info = queryPathInfo(path);
- if (!info->deriver) return nullptr;
+ if (!info->deriver) return std::nullopt;
path = *info->deriver;
} catch (InvalidPath &) {
- return nullptr;
+ return std::nullopt;
}
}
- auto baseName = std::string(baseNameOf(printStorePath(path)));
+ auto baseName = path.to_string();
for (int j = 0; j < 2; j++) {
Path logPath =
j == 0
- ? fmt("%s/%s/%s/%s", logDir, drvsLogDir, string(baseName, 0, 2), string(baseName, 2))
+ ? fmt("%s/%s/%s/%s", logDir, drvsLogDir, baseName.substr(0, 2), baseName.substr(2))
: fmt("%s/%s/%s", logDir, drvsLogDir, baseName);
Path logBz2Path = logPath + ".bz2";
if (pathExists(logPath))
- return std::make_shared<std::string>(readFile(logPath));
+ return readFile(logPath);
else if (pathExists(logBz2Path)) {
try {
@@ -124,7 +122,7 @@ std::shared_ptr<std::string> LocalFSStore::getBuildLog(const StorePath & path_)
}
- return nullptr;
+ return std::nullopt;
}
}
diff --git a/src/libstore/local-fs-store.hh b/src/libstore/local-fs-store.hh
index f8b19d00d..e44b27cc2 100644
--- a/src/libstore/local-fs-store.hh
+++ b/src/libstore/local-fs-store.hh
@@ -45,7 +45,8 @@ public:
return getRealStoreDir() + "/" + std::string(storePath, storeDir.size() + 1);
}
- std::shared_ptr<std::string> getBuildLog(const StorePath & path) override;
+ std::optional<std::string> getBuildLog(const StorePath & path) override;
+
};
}
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 9ebdfd6ed..d3cebe720 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -1461,12 +1461,12 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s,
StringSink sink;
dumpString(s, sink);
- auto narHash = hashString(htSHA256, *sink.s);
+ auto narHash = hashString(htSHA256, sink.s);
optimisePath(realPath, repair);
ValidPathInfo info { dstPath, narHash };
- info.narSize = sink.s->size();
+ info.narSize = sink.s.size();
info.references = references;
info.ca = TextHash { .hash = hash };
registerValidPath(info);
diff --git a/src/libstore/nar-accessor.cc b/src/libstore/nar-accessor.cc
index 784ebb719..7d27d7667 100644
--- a/src/libstore/nar-accessor.cc
+++ b/src/libstore/nar-accessor.cc
@@ -28,7 +28,7 @@ struct NarMember
struct NarAccessor : public FSAccessor
{
- std::shared_ptr<const std::string> nar;
+ std::optional<const std::string> nar;
GetNarBytes getNarBytes;
@@ -104,7 +104,7 @@ struct NarAccessor : public FSAccessor
}
};
- NarAccessor(ref<const std::string> nar) : nar(nar)
+ NarAccessor(std::string && _nar) : nar(_nar)
{
StringSource source(*nar);
NarIndexer indexer(*this, source);
@@ -224,9 +224,9 @@ struct NarAccessor : public FSAccessor
}
};
-ref<FSAccessor> makeNarAccessor(ref<const std::string> nar)
+ref<FSAccessor> makeNarAccessor(std::string && nar)
{
- return make_ref<NarAccessor>(nar);
+ return make_ref<NarAccessor>(std::move(nar));
}
ref<FSAccessor> makeNarAccessor(Source & source)
diff --git a/src/libstore/nar-accessor.hh b/src/libstore/nar-accessor.hh
index 8af1272f6..c2241a04c 100644
--- a/src/libstore/nar-accessor.hh
+++ b/src/libstore/nar-accessor.hh
@@ -10,7 +10,7 @@ struct Source;
/* Return an object that provides access to the contents of a NAR
file. */
-ref<FSAccessor> makeNarAccessor(ref<const std::string> nar);
+ref<FSAccessor> makeNarAccessor(std::string && nar);
ref<FSAccessor> makeNarAccessor(Source & source);
diff --git a/src/libstore/remote-fs-accessor.cc b/src/libstore/remote-fs-accessor.cc
index f43456f0b..0ce335646 100644
--- a/src/libstore/remote-fs-accessor.cc
+++ b/src/libstore/remote-fs-accessor.cc
@@ -22,9 +22,18 @@ Path RemoteFSAccessor::makeCacheFile(std::string_view hashPart, const std::strin
return fmt("%s/%s.%s", cacheDir, hashPart, ext);
}
-void RemoteFSAccessor::addToCache(std::string_view hashPart, const std::string & nar,
- ref<FSAccessor> narAccessor)
+ref<FSAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std::string && nar)
{
+ if (cacheDir != "") {
+ try {
+ /* FIXME: do this asynchronously. */
+ writeFile(makeCacheFile(hashPart, "nar"), nar);
+ } catch (...) {
+ ignoreException();
+ }
+ }
+
+ auto narAccessor = makeNarAccessor(std::move(nar));
nars.emplace(hashPart, narAccessor);
if (cacheDir != "") {
@@ -33,14 +42,12 @@ void RemoteFSAccessor::addToCache(std::string_view hashPart, const std::string &
JSONPlaceholder jsonRoot(str);
listNar(jsonRoot, narAccessor, "", true);
writeFile(makeCacheFile(hashPart, "ls"), str.str());
-
- /* FIXME: do this asynchronously. */
- writeFile(makeCacheFile(hashPart, "nar"), nar);
-
} catch (...) {
ignoreException();
}
}
+
+ return narAccessor;
}
std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_, bool requireValidPath)
@@ -55,7 +62,6 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_, boo
auto i = nars.find(std::string(storePath.hashPart()));
if (i != nars.end()) return {i->second, restPath};
- StringSink sink;
std::string listing;
Path cacheFile;
@@ -86,19 +92,15 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_, boo
} catch (SysError &) { }
try {
- *sink.s = nix::readFile(cacheFile);
-
- auto narAccessor = makeNarAccessor(sink.s);
+ auto narAccessor = makeNarAccessor(nix::readFile(cacheFile));
nars.emplace(storePath.hashPart(), narAccessor);
return {narAccessor, restPath};
-
} catch (SysError &) { }
}
+ StringSink sink;
store->narFromPath(storePath, sink);
- auto narAccessor = makeNarAccessor(sink.s);
- addToCache(storePath.hashPart(), *sink.s, narAccessor);
- return {narAccessor, restPath};
+ return {addToCache(storePath.hashPart(), std::move(sink.s)), restPath};
}
FSAccessor::Stat RemoteFSAccessor::stat(const Path & path)
diff --git a/src/libstore/remote-fs-accessor.hh b/src/libstore/remote-fs-accessor.hh
index 594852d0e..99f5544ef 100644
--- a/src/libstore/remote-fs-accessor.hh
+++ b/src/libstore/remote-fs-accessor.hh
@@ -20,8 +20,7 @@ class RemoteFSAccessor : public FSAccessor
Path makeCacheFile(std::string_view hashPart, const std::string & ext);
- void addToCache(std::string_view hashPart, const std::string & nar,
- ref<FSAccessor> narAccessor);
+ ref<FSAccessor> addToCache(std::string_view hashPart, std::string && nar);
public:
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 57cc260b0..6886103e1 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -172,7 +172,7 @@ void RemoteStore::initConnection(Connection & conn)
it. */
conn.closeWrite();
auto msg = conn.from.drain();
- throw Error("protocol mismatch, got '%s'", chomp(*saved.s + msg));
+ throw Error("protocol mismatch, got '%s'", chomp(saved.s + msg));
}
conn.from >> conn.daemonVersion;
diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc
index 7accad7f4..a024e971d 100644
--- a/src/libstore/s3-binary-cache-store.cc
+++ b/src/libstore/s3-binary-cache-store.cc
@@ -385,7 +385,7 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual
auto compress = [&](std::string compression)
{
auto compressed = nix::compress(compression, StreamToSourceAdapter(istream).drain());
- return std::make_shared<std::stringstream>(std::move(*compressed));
+ return std::make_shared<std::stringstream>(std::move(compressed));
};
if (narinfoCompression != "" && hasSuffix(path, ".narinfo"))
diff --git a/src/libstore/s3.hh b/src/libstore/s3.hh
index 2042bffcf..3f55c74db 100644
--- a/src/libstore/s3.hh
+++ b/src/libstore/s3.hh
@@ -4,6 +4,8 @@
#include "ref.hh"
+#include <optional>
+
namespace Aws { namespace Client { class ClientConfiguration; } }
namespace Aws { namespace S3 { class S3Client; } }
@@ -20,7 +22,7 @@ struct S3Helper
struct FileTransferResult
{
- std::shared_ptr<std::string> data;
+ std::optional<std::string> data;
unsigned int durationMs;
};
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 3dd446f23..3567dcd1c 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -724,8 +724,8 @@ public:
/* Return the build log of the specified store path, if available,
or null otherwise. */
- virtual std::shared_ptr<std::string> getBuildLog(const StorePath & path)
- { return nullptr; }
+ virtual std::optional<std::string> getBuildLog(const StorePath & path)
+ { return std::nullopt; }
/* Hack to allow long-running processes like hydra-queue-runner to
occasionally flush their path info cache. */