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:
		
							parent
							
								
									d52d889f2b
								
							
						
					
					
						commit
						849966d614
					
				
					 1 changed files with 17 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue