mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
LocalBinaryCacheStore::upsertFile(): Fix race
When multiple threads try to upsert the same file, this could fail. Fixes #4667.
This commit is contained in:
parent
4638bcfb2c
commit
dd77f71afe
2 changed files with 7 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
|||
#include "globals.hh"
|
||||
#include "nar-info-disk-cache.hh"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace nix {
|
||||
|
||||
struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
|
||||
|
@ -50,7 +52,8 @@ protected:
|
|||
const std::string & mimeType) override
|
||||
{
|
||||
auto path2 = binaryCacheDir + "/" + path;
|
||||
Path tmp = path2 + ".tmp." + std::to_string(getpid());
|
||||
static std::atomic<int> counter{0};
|
||||
Path tmp = fmt("%s.tmp.%d.%d", path2, getpid(), ++counter);
|
||||
AutoDelete del(tmp, false);
|
||||
StreamToSourceAdapter source(istream);
|
||||
writeFile(tmp, source);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue