diff options
author | Florian Klink <flokli@flokli.de> | 2024-10-18T16·00+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-10-19T09·41+0000 |
commit | 849966d61418b2f1f27cddc7e7b7dedd1e9c2e5d (patch) | |
tree | 62cf46255be339b487d940e8f13638bd6d494c78 | |
parent | d52d889f2bf6ff0aa329c3058120140da2debaf7 (diff) |
refactor(tvix/store/pathinfo/signing_wrapper): remove clone r/8838
Construct the owned signature in a separate scope, so all borrows to the original PathInfo are already dropped again, and we can modify the PathInfo without having to clone it. Change-Id: I03e7390540c2cfe7a2c61850bdbe8a33d213a5d9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12663 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
-rw-r--r-- | tvix/store/src/pathinfoservice/signing_wrapper.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/tvix/store/src/pathinfoservice/signing_wrapper.rs b/tvix/store/src/pathinfoservice/signing_wrapper.rs index 5898a5baa463..525e60e416a8 100644 --- a/tvix/store/src/pathinfoservice/signing_wrapper.rs +++ b/tvix/store/src/pathinfoservice/signing_wrapper.rs @@ -50,15 +50,23 @@ where self.inner.get(digest).await } - async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error> { - let mut path_info = path_info.clone(); - let mut nar_info = path_info.to_narinfo(); - nar_info.add_signature(self.signing_key.as_ref()); - path_info.signatures = nar_info - .signatures - .into_iter() - .map(|s| Signature::<String>::new(s.name().to_string(), s.bytes().to_owned())) - .collect(); + async fn put(&self, mut path_info: PathInfo) -> Result<PathInfo, Error> { + path_info.signatures.push({ + let mut nar_info = path_info.to_narinfo(); + nar_info.signatures.clear(); + nar_info.add_signature(self.signing_key.as_ref()); + + let s = nar_info + .signatures + .pop() + .expect("Tvix bug: no signature after signing op"); + debug_assert!( + nar_info.signatures.is_empty(), + "Tvix bug: more than one signature appeared" + ); + + Signature::new(s.name().to_string(), *s.bytes()) + }); self.inner.put(path_info).await } |