1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-13 14:02:42 +01:00

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
This commit is contained in:
Théophane Hufschmitt 2022-04-11 10:20:36 +02:00
parent 5d47c37cbc
commit 93739ce006

View file

@ -197,15 +197,19 @@ TraceResult followPathsToStore(GlobalOpts opts, set<fs::path> roots)
*/ */
void scanFileContent(const GlobalOpts & opts, const fs::path & fileToScan, Roots & res) void scanFileContent(const GlobalOpts & opts, const fs::path & fileToScan, Roots & res)
{ {
std::ostringstream contentStream;
{
std::ifstream fs; std::ifstream fs;
fs.open(fileToScan); fs.open(fileToScan);
std::string content; fs >> contentStream.rdbuf();
fs >> content; }
auto fileEnd = std::sregex_iterator(); std::string content = contentStream.str();
auto regex = storePathRegex(opts.storeDir); auto regex = storePathRegex(opts.storeDir);
auto firstMatch = std::sregex_iterator(content.begin(), content.end(), regex); auto firstMatch
for (auto & i = firstMatch; i != fileEnd; i++) = std::sregex_iterator { content.begin(), content.end(), regex };
res[i->str()].insert(fileToScan); auto fileEnd = std::sregex_iterator{};
for (auto i = firstMatch; i != fileEnd; ++i)
res[i->str()].emplace(fileToScan);
} }
/** /**