From 3fa1e7daced316a5a396dc0cb74dc2f7a89b5f60 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 27 Mar 2020 16:15:50 +0100 Subject: [PATCH] Fix diffLockFiles() --- src/libexpr/flake/lockfile.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index b7a9e20c1..ee04ec64f 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -96,8 +96,6 @@ StorePath LockedNode::computeStorePath(Store & store) const std::shared_ptr Node::findInput(const InputPath & path) { - assert(!path.empty()); - auto pos = shared_from_this(); for (auto & elem : path) { @@ -275,32 +273,33 @@ InputPath parseInputPath(std::string_view s) path.push_back(elem); } - if (path.empty()) - throw Error("flake input path is empty"); - return path; } static void flattenLockFile( std::shared_ptr node, const InputPath & prefix, + std::unordered_set> & done, std::map> & res) { - // FIXME: handle cycles + if (!done.insert(node).second) return; + for (auto &[id, input] : node->inputs) { auto inputPath(prefix); inputPath.push_back(id); if (auto lockedInput = std::dynamic_pointer_cast(input)) res.emplace(inputPath, lockedInput); - flattenLockFile(input, inputPath, res); + flattenLockFile(input, inputPath, done, res); } } std::string diffLockFiles(const LockFile & oldLocks, const LockFile & newLocks) { + std::unordered_set> done; std::map> oldFlat, newFlat; - flattenLockFile(oldLocks.root, {}, oldFlat); - flattenLockFile(newLocks.root, {}, newFlat); + flattenLockFile(oldLocks.root, {}, done, oldFlat); + done.clear(); + flattenLockFile(newLocks.root, {}, done, newFlat); auto i = oldFlat.begin(); auto j = newFlat.begin();