2012-07-18 21:59:03 +03:00
|
|
|
#pragma once
|
2003-07-14 13:23:11 +03:00
|
|
|
|
2009-03-28 22:51:33 +02:00
|
|
|
#include "hash.hh"
|
2021-10-04 14:47:38 +03:00
|
|
|
#include "path.hh"
|
2003-07-14 13:23:11 +03:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
namespace nix {
|
2003-07-14 13:23:11 +03:00
|
|
|
|
2021-10-04 14:47:38 +03:00
|
|
|
std::pair<StorePathSet, HashResult> scanForReferences(const Path & path, const StorePathSet & refs);
|
2018-03-30 01:56:13 +03:00
|
|
|
|
2021-10-04 14:47:38 +03:00
|
|
|
StorePathSet scanForReferences(Sink & toTee, const Path & path, const StorePathSet & refs);
|
2020-08-07 22:09:26 +03:00
|
|
|
|
2021-10-04 15:29:42 +03:00
|
|
|
class RefScanSink : public Sink
|
|
|
|
{
|
|
|
|
StringSet hashes;
|
|
|
|
StringSet seen;
|
|
|
|
|
|
|
|
std::string tail;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
RefScanSink(StringSet && hashes) : hashes(hashes)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
StringSet & getResult()
|
|
|
|
{ return seen; }
|
|
|
|
|
|
|
|
void operator () (std::string_view data) override;
|
|
|
|
};
|
|
|
|
|
2022-11-04 15:19:31 +02:00
|
|
|
class PathRefScanSink : public RefScanSink
|
|
|
|
{
|
|
|
|
std::map<std::string, StorePath> backMap;
|
|
|
|
|
|
|
|
PathRefScanSink(StringSet && hashes, std::map<std::string, StorePath> && backMap);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static PathRefScanSink fromPaths(const StorePathSet & refs);
|
|
|
|
|
|
|
|
StorePathSet getResultPaths();
|
|
|
|
};
|
|
|
|
|
2018-03-30 01:56:13 +03:00
|
|
|
struct RewritingSink : Sink
|
|
|
|
{
|
|
|
|
std::string from, to, prev;
|
|
|
|
Sink & nextSink;
|
|
|
|
uint64_t pos = 0;
|
|
|
|
|
|
|
|
std::vector<uint64_t> matches;
|
|
|
|
|
|
|
|
RewritingSink(const std::string & from, const std::string & to, Sink & nextSink);
|
|
|
|
|
2020-12-02 15:00:43 +02:00
|
|
|
void operator () (std::string_view data) override;
|
2018-03-30 01:56:13 +03:00
|
|
|
|
|
|
|
void flush();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HashModuloSink : AbstractHashSink
|
|
|
|
{
|
|
|
|
HashSink hashSink;
|
|
|
|
RewritingSink rewritingSink;
|
|
|
|
|
|
|
|
HashModuloSink(HashType ht, const std::string & modulus);
|
|
|
|
|
2020-12-02 15:00:43 +02:00
|
|
|
void operator () (std::string_view data) override;
|
2018-03-30 01:56:13 +03:00
|
|
|
|
|
|
|
HashResult finish() override;
|
|
|
|
};
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
}
|