Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9c00fa417923
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2965d40612e1
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 11, 2017

  1. Copy the full SHA
    8e8caf7 View commit details
  2. replaceSymlink(): Handle the case where the temporary file already ex…

    …ists
    
    Not really necessary anymore for #849, but still nice to have.
    edolstra committed Jul 11, 2017
    Copy the full SHA
    2965d40 View commit details
Showing with 17 additions and 4 deletions.
  1. +4 −0 src/libstore/download.cc
  2. +13 −4 src/libutil/util.cc
4 changes: 4 additions & 0 deletions src/libstore/download.cc
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
#include "archive.hh"
#include "s3.hh"
#include "compression.hh"
#include "pathlocks.hh"

#ifdef ENABLE_S3
#include <aws/core/client/ClientConfiguration.h>
@@ -586,6 +587,8 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
Path dataFile = cacheDir + "/" + urlHash + ".info";
Path fileLink = cacheDir + "/" + urlHash + "-file";

PathLocks lock({fileLink}, fmt("waiting for lock on ‘%1%’...", fileLink));

Path storePath;

string expectedETag;
@@ -647,6 +650,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa

if (unpack) {
Path unpackedLink = cacheDir + "/" + baseNameOf(storePath) + "-unpacked";
PathLocks lock2({unpackedLink}, fmt("waiting for lock on ‘%1%’...", unpackedLink));
Path unpackedStorePath;
if (pathExists(unpackedLink)) {
unpackedStorePath = readLink(unpackedLink);
17 changes: 13 additions & 4 deletions src/libutil/util.cc
Original file line number Diff line number Diff line change
@@ -496,12 +496,21 @@ void createSymlink(const Path & target, const Path & link)

void replaceSymlink(const Path & target, const Path & link)
{
Path tmp = canonPath(dirOf(link) + "/.new_" + baseNameOf(link));
for (unsigned int n = 0; true; n++) {
Path tmp = canonPath(fmt("%s/.%d_%s", dirOf(link), n, baseNameOf(link)));

createSymlink(target, tmp);
try {
createSymlink(target, tmp);
} catch (SysError & e) {
if (e.errNo == EEXIST) continue;
throw;
}

if (rename(tmp.c_str(), link.c_str()) != 0)
throw SysError(format("renaming ‘%1%’ to ‘%2%’") % tmp % link);
if (rename(tmp.c_str(), link.c_str()) != 0)
throw SysError(format("renaming ‘%1%’ to ‘%2%’") % tmp % link);

break;
}
}