aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-21 14:55:43 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-21 14:55:43 +0200
commit20a1a65d377cb49dd0a1b60a07623760bfc730d1 (patch)
tree38b64f1584bb5cf2c744933eecfe1c0c64ce4f3f /src/libexpr/primops
parent818c8da5b88c5486026dd377b384e9121bb68de5 (diff)
Only rewrite the lockfile if it changed
This removes spurious warnings about failure to write the lockfile.
Diffstat (limited to 'src/libexpr/primops')
-rw-r--r--src/libexpr/primops/flake.cc30
-rw-r--r--src/libexpr/primops/flake.hh21
2 files changed, 38 insertions, 13 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index 3cbb0c1ef..788977c72 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -465,31 +465,35 @@ ResolvedFlake resolveFlakeFromLockFile(EvalState & state, const FlakeRef & flake
ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLockFile handleLockFile)
{
Flake flake = getFlake(state, topRef, allowedToUseRegistries(handleLockFile, true));
- LockFile lockFile;
+ LockFile oldLockFile;
if (!recreateLockFile (handleLockFile)) {
// If recreateLockFile, start with an empty lockfile
- lockFile = readLockFile(flake.storePath + "/flake.lock"); // FIXME: symlink attack
+ oldLockFile = readLockFile(flake.storePath + "/flake.lock"); // FIXME: symlink attack
}
+ LockFile lockFile(oldLockFile);
+
ResolvedFlake resFlake = resolveFlakeFromLockFile(state, topRef, handleLockFile, lockFile, true);
lockFile = entryToLockFile(dependenciesToFlakeEntry(resFlake));
- if (allowedToWrite(handleLockFile)) {
- if (auto refData = std::get_if<FlakeRef::IsPath>(&topRef.data)) {
- writeLockFile(lockFile, refData->path + (topRef.subdir == "" ? "" : "/" + topRef.subdir) + "/flake.lock");
-
- // Hack: Make sure that flake.lock is visible to Git, so it ends up in the Nix store.
- runProgram("git", true, { "-C", refData->path, "add",
- (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock" });
- } else std::cout << "Cannot write lockfile because the FlakeRef isn't of the form IsPath." << std::endl;
- } else if (handleLockFile != AllPure && handleLockFile != TopRefUsesRegistries)
- std::cout << "Using updating lockfile without writing it to file" << std::endl;
+ if (!(lockFile == oldLockFile)) {
+ if (allowedToWrite(handleLockFile)) {
+ if (auto refData = std::get_if<FlakeRef::IsPath>(&topRef.data)) {
+ writeLockFile(lockFile, refData->path + (topRef.subdir == "" ? "" : "/" + topRef.subdir) + "/flake.lock");
+
+ // Hack: Make sure that flake.lock is visible to Git, so it ends up in the Nix store.
+ runProgram("git", true, { "-C", refData->path, "add",
+ (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock" });
+ } else std::cout << "Cannot write lockfile because the FlakeRef isn't of the form IsPath." << std::endl;
+ } else if (handleLockFile != AllPure && handleLockFile != TopRefUsesRegistries)
+ std::cout << "Using updating lockfile without writing it to file" << std::endl;
+ }
return resFlake;
}
-void updateLockFile (EvalState & state, const FlakeUri & flakeUri, bool recreateLockFile)
+void updateLockFile(EvalState & state, const FlakeUri & flakeUri, bool recreateLockFile)
{
FlakeRef flakeRef(flakeUri);
resolveFlake(state, flakeRef, recreateLockFile ? RecreateLockFile : UpdateLockFile);
diff --git a/src/libexpr/primops/flake.hh b/src/libexpr/primops/flake.hh
index 6f91686a6..e43b860ee 100644
--- a/src/libexpr/primops/flake.hh
+++ b/src/libexpr/primops/flake.hh
@@ -24,6 +24,11 @@ struct LockFile
FlakeRef ref;
Hash contentHash;
NonFlakeEntry(const FlakeRef & flakeRef, const Hash & hash) : ref(flakeRef), contentHash(hash) {};
+
+ bool operator ==(const NonFlakeEntry & other) const
+ {
+ return ref == other.ref && contentHash == other.contentHash;
+ }
};
struct FlakeEntry
@@ -33,10 +38,26 @@ struct LockFile
std::map<FlakeRef, FlakeEntry> flakeEntries;
std::map<FlakeAlias, NonFlakeEntry> nonFlakeEntries;
FlakeEntry(const FlakeRef & flakeRef, const Hash & hash) : ref(flakeRef), contentHash(hash) {};
+
+ bool operator ==(const FlakeEntry & other) const
+ {
+ return
+ ref == other.ref
+ && contentHash == other.contentHash
+ && flakeEntries == other.flakeEntries
+ && nonFlakeEntries == other.nonFlakeEntries;
+ }
};
std::map<FlakeRef, FlakeEntry> flakeEntries;
std::map<FlakeAlias, NonFlakeEntry> nonFlakeEntries;
+
+ bool operator ==(const LockFile & other) const
+ {
+ return
+ flakeEntries == other.flakeEntries
+ && nonFlakeEntries == other.nonFlakeEntries;
+ }
};
typedef std::vector<std::shared_ptr<FlakeRegistry>> Registries;