diff --git a/src/libstore/build/find-cycles.cc b/src/libstore/build/find-cycles.cc index 208e988d2..4eb4a604d 100644 --- a/src/libstore/build/find-cycles.cc +++ b/src/libstore/build/find-cycles.cc @@ -26,22 +26,21 @@ CycleEdgeScanSink::CycleEdgeScanSink( void CycleEdgeScanSink::setCurrentPath(const std::string & path) { currentFilePath = path; + // Clear tracking for new file + recordedForCurrentFile.clear(); } void CycleEdgeScanSink::operator()(std::string_view data) { - // Track what hashes we've already seen - auto seenBefore = getResult(); - // Call parent's operator() to do the actual hash searching // This reuses all the proven buffer boundary handling logic RefScanSink::operator()(data); - // Check for newly found hashes - auto seenAfter = getResult(); - for (const auto & hash : seenAfter) { - if (seenBefore.find(hash) == seenBefore.end()) { - // This hash was just found in the current file + // Check which hashes have been found and not yet recorded for this file + // getResult() returns the set of ALL hashes found so far + for (const auto & hash : getResult()) { + if (recordedForCurrentFile.insert(hash).second) { + // This hash was just found and not yet recorded for current file // Create an edge from current file to the target auto targetPath = storeDir + hash; diff --git a/src/libstore/build/find-cycles.hh b/src/libstore/build/find-cycles.hh index 7440cc3f2..dd38b1fea 100644 --- a/src/libstore/build/find-cycles.hh +++ b/src/libstore/build/find-cycles.hh @@ -38,6 +38,10 @@ class CycleEdgeScanSink : public RefScanSink std::map hashPathMap; std::string storeDir; + // Track hashes we've already recorded for current file + // to avoid duplicates + StringSet recordedForCurrentFile; + public: StoreCycleEdgeVec edges;