From 93739ce0066ac3c85fc541f6a68e7e0c07166d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Mon, 11 Apr 2022 10:20:36 +0200 Subject: [PATCH] Dump the whole file when scaning its content Dumping the fstream to a string just dumps a certain number of bits of it, causing some references to be missed --- src/nix-find-roots/nix-find-roots.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/nix-find-roots/nix-find-roots.cc b/src/nix-find-roots/nix-find-roots.cc index 168a2416a..06b5f272f 100644 --- a/src/nix-find-roots/nix-find-roots.cc +++ b/src/nix-find-roots/nix-find-roots.cc @@ -197,15 +197,19 @@ TraceResult followPathsToStore(GlobalOpts opts, set roots) */ void scanFileContent(const GlobalOpts & opts, const fs::path & fileToScan, Roots & res) { - std::ifstream fs; - fs.open(fileToScan); - std::string content; - fs >> content; - auto fileEnd = std::sregex_iterator(); + std::ostringstream contentStream; + { + std::ifstream fs; + fs.open(fileToScan); + fs >> contentStream.rdbuf(); + } + std::string content = contentStream.str(); auto regex = storePathRegex(opts.storeDir); - auto firstMatch = std::sregex_iterator(content.begin(), content.end(), regex); - for (auto & i = firstMatch; i != fileEnd; i++) - res[i->str()].insert(fileToScan); + auto firstMatch + = std::sregex_iterator { content.begin(), content.end(), regex }; + auto fileEnd = std::sregex_iterator{}; + for (auto i = firstMatch; i != fileEnd; ++i) + res[i->str()].emplace(fileToScan); } /**