From 849966d61418b2f1f27cddc7e7b7dedd1e9c2e5d Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 18 Oct 2024 18:00:01 +0200 Subject: [PATCH] refactor(tvix/store/pathinfo/signing_wrapper): remove clone 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 Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- .../src/pathinfoservice/signing_wrapper.rs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tvix/store/src/pathinfoservice/signing_wrapper.rs b/tvix/store/src/pathinfoservice/signing_wrapper.rs index 5898a5baa..525e60e41 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 { - 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::::new(s.name().to_string(), s.bytes().to_owned())) - .collect(); + async fn put(&self, mut path_info: PathInfo) -> Result { + 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 }