aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/local-binary-cache-store.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-08-03 21:02:28 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-08-03 21:02:28 +0000
commit062533f7cdb74026096ca8c7d5b6e393893d59ef (patch)
treecca64de7b3581072d1d9ecd11a31b053de68f6d5 /src/libstore/local-binary-cache-store.cc
parentd92d4f85a5c8a2a2385c084500a8b6bd54b54e6c (diff)
parenta2842588ec86a0f488a385d453eda86e1f52f05a (diff)
Merge remote-tracking branch 'upstream/master' into path-info-header
Diffstat (limited to 'src/libstore/local-binary-cache-store.cc')
-rw-r--r--src/libstore/local-binary-cache-store.cc35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc
index 48aca478c..87d8334d7 100644
--- a/src/libstore/local-binary-cache-store.cc
+++ b/src/libstore/local-binary-cache-store.cc
@@ -31,8 +31,18 @@ protected:
bool fileExists(const std::string & path) override;
void upsertFile(const std::string & path,
- const std::string & data,
- const std::string & mimeType) override;
+ std::shared_ptr<std::basic_iostream<char>> istream,
+ const std::string & mimeType) override
+ {
+ auto path2 = binaryCacheDir + "/" + path;
+ Path tmp = path2 + ".tmp." + std::to_string(getpid());
+ AutoDelete del(tmp, false);
+ StreamToSourceAdapter source(istream);
+ writeFile(tmp, source);
+ if (rename(tmp.c_str(), path2.c_str()))
+ throw SysError("renaming '%1%' to '%2%'", tmp, path2);
+ del.cancel();
+ }
void getFile(const std::string & path, Sink & sink) override
{
@@ -52,7 +62,9 @@ protected:
if (entry.name.size() != 40 ||
!hasSuffix(entry.name, ".narinfo"))
continue;
- paths.insert(parseStorePath(storeDir + "/" + entry.name.substr(0, entry.name.size() - 8)));
+ paths.insert(parseStorePath(
+ storeDir + "/" + entry.name.substr(0, entry.name.size() - 8)
+ + "-" + MissingName));
}
return paths;
@@ -68,28 +80,11 @@ void LocalBinaryCacheStore::init()
BinaryCacheStore::init();
}
-static void atomicWrite(const Path & path, const std::string & s)
-{
- Path tmp = path + ".tmp." + std::to_string(getpid());
- AutoDelete del(tmp, false);
- writeFile(tmp, s);
- if (rename(tmp.c_str(), path.c_str()))
- throw SysError("renaming '%1%' to '%2%'", tmp, path);
- del.cancel();
-}
-
bool LocalBinaryCacheStore::fileExists(const std::string & path)
{
return pathExists(binaryCacheDir + "/" + path);
}
-void LocalBinaryCacheStore::upsertFile(const std::string & path,
- const std::string & data,
- const std::string & mimeType)
-{
- atomicWrite(binaryCacheDir + "/" + path, data);
-}
-
static RegisterStoreImplementation regStore([](
const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>