mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
Only rewrite the lockfile if it changed
This removes spurious warnings about failure to write the lockfile.
This commit is contained in:
parent
818c8da5b8
commit
20a1a65d37
2 changed files with 37 additions and 12 deletions
|
@ -465,16 +465,19 @@ 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 (!(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");
|
||||
|
@ -485,11 +488,12 @@ ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLoc
|
|||
} 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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue