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 <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
Florian Klink 2024-10-18 18:00:01 +02:00 committed by clbot
parent d52d889f2b
commit 849966d614

View file

@ -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
}