aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/references.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-05-02 03:09:51 +0200
committereldritch horrors <pennae@lix.systems>2024-07-06 12:36:37 +0200
commit55a32f24d3285c0b4f6866e16a4c8aeac6345c02 (patch)
tree98c40d476fc69913f40fc12c7a3dfec8f13f7109 /src/libutil/references.cc
parent5af76dee371ea5fa1eb72141370fdf18851d67c7 (diff)
libutil: remove RewritingSink match/size tracking
size tracking can be done with a LengthSink and a tee. match tracking was defeated by never having done any match tracking, all users would see the same (empty) set of matches at all times. match tracking with bytes offsets alone would not be sufficient in the general case, only because computeHashModulo uses a single rewrite could it have worked. Change-Id: Idb214b5222e0ea24f450f5505712a342b63d7570
Diffstat (limited to 'src/libutil/references.cc')
-rw-r--r--src/libutil/references.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/libutil/references.cc b/src/libutil/references.cc
index 249c78bf7..8792578d4 100644
--- a/src/libutil/references.cc
+++ b/src/libutil/references.cc
@@ -96,15 +96,12 @@ void RewritingSink::operator () (std::string_view data)
auto consumed = s.size() - prev.size();
- pos += consumed;
-
if (consumed) nextSink(s.substr(0, consumed));
}
void RewritingSink::flush()
{
if (prev.empty()) return;
- pos += prev.size();
nextSink(prev);
prev.clear();
}
@@ -112,20 +109,23 @@ void RewritingSink::flush()
HashResult computeHashModulo(HashType ht, const std::string & modulus, Source & source)
{
HashSink hashSink(ht);
+ LengthSink lengthSink;
RewritingSink rewritingSink(modulus, std::string(modulus.size(), 0), hashSink);
- source.drainInto(rewritingSink);
+ TeeSink tee{rewritingSink, lengthSink};
+ source.drainInto(tee);
rewritingSink.flush();
/* Hash the positions of the self-references. This ensures that a
NAR with self-references and a NAR with some of the
self-references already zeroed out do not produce a hash
collision. FIXME: proof. */
- for (auto & pos : rewritingSink.matches)
- hashSink(fmt("|%d", pos));
+ // NOTE(horrors) RewritingSink didn't track any matches!
+ //for (auto & pos : rewritingSource.matches)
+ // hashSink(fmt("|%d", pos));
auto h = hashSink.finish();
- return {h.first, rewritingSink.pos};
+ return {h.first, lengthSink.length};
}
}