mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
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.
This commit is contained in:
parent
99851c6f06
commit
d1b0909894
11 changed files with 52 additions and 28 deletions
|
@ -22,7 +22,7 @@ protected:
|
|||
|
||||
void upsertFile(const std::string & path, const std::string & data) override;
|
||||
|
||||
std::string getFile(const std::string & path) override;
|
||||
std::shared_ptr<std::string> getFile(const std::string & path) override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -59,9 +59,14 @@ void LocalBinaryCacheStore::upsertFile(const std::string & path, const std::stri
|
|||
atomicWrite(binaryCacheDir + "/" + path, data);
|
||||
}
|
||||
|
||||
std::string LocalBinaryCacheStore::getFile(const std::string & path)
|
||||
std::shared_ptr<std::string> LocalBinaryCacheStore::getFile(const std::string & path)
|
||||
{
|
||||
return readFile(binaryCacheDir + "/" + path);
|
||||
try {
|
||||
return std::make_shared<std::string>(readFile(binaryCacheDir + "/" + path));
|
||||
} catch (SysError & e) {
|
||||
if (e.errNo == ENOENT) return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
ref<Store> openLocalBinaryCacheStore(std::shared_ptr<Store> localStore,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue