@@ -3,7 +3,7 @@ use std::process::Command;
33pub mod image;
44pub mod tar;
55
6- use std:: { collections:: HashMap , io:: Read , iter:: zip, path:: Path } ;
6+ use std:: { collections:: HashMap , io:: Read , iter:: zip, path:: Path , sync :: Arc } ;
77
88use anyhow:: { bail, ensure, Context , Result } ;
99use async_compression:: tokio:: bufread:: { GzipDecoder , ZstdDecoder } ;
@@ -23,7 +23,7 @@ use crate::{
2323} ;
2424
2525pub fn import_layer < ObjectID : FsVerityHashValue > (
26- repo : & Repository < ObjectID > ,
26+ repo : & Arc < Repository < ObjectID > > ,
2727 sha256 : & Sha256Digest ,
2828 name : Option < & str > ,
2929 tar_stream : & mut impl Read ,
@@ -44,8 +44,8 @@ pub fn ls_layer<ObjectID: FsVerityHashValue>(
4444 Ok ( ( ) )
4545}
4646
47- struct ImageOp < ' repo , ObjectID : FsVerityHashValue > {
48- repo : & ' repo Repository < ObjectID > ,
47+ struct ImageOp < ObjectID : FsVerityHashValue > {
48+ repo : Arc < Repository < ObjectID > > ,
4949 proxy : ImageProxy ,
5050 img : OpenedImage ,
5151 progress : MultiProgress ,
@@ -67,8 +67,8 @@ fn sha256_from_digest(digest: &str) -> Result<Sha256Digest> {
6767
6868type ContentAndVerity < ObjectID > = ( Sha256Digest , ObjectID ) ;
6969
70- impl < ' repo , ObjectID : FsVerityHashValue > ImageOp < ' repo , ObjectID > {
71- async fn new ( repo : & ' repo Repository < ObjectID > , imgref : & str ) -> Result < Self > {
70+ impl < ObjectID : FsVerityHashValue > ImageOp < ObjectID > {
71+ async fn new ( repo : & Arc < Repository < ObjectID > > , imgref : & str ) -> Result < Self > {
7272 // See https://github.com/containers/skopeo/issues/2563
7373 let skopeo_cmd = if imgref. starts_with ( "containers-storage:" ) {
7474 let mut cmd = Command :: new ( "podman" ) ;
@@ -87,7 +87,7 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
8787 let img = proxy. open_image ( imgref) . await . context ( "Opening image" ) ?;
8888 let progress = MultiProgress :: new ( ) ;
8989 Ok ( ImageOp {
90- repo,
90+ repo : Arc :: clone ( repo ) ,
9191 proxy,
9292 img,
9393 progress,
@@ -142,7 +142,7 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
142142 }
143143
144144 pub async fn ensure_config (
145- & self ,
145+ self : & Arc < Self > ,
146146 manifest_layers : & [ Descriptor ] ,
147147 descriptor : & Descriptor ,
148148 ) -> Result < ContentAndVerity < ObjectID > > {
@@ -192,7 +192,7 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
192192 }
193193 }
194194
195- pub async fn pull ( & self ) -> Result < ContentAndVerity < ObjectID > > {
195+ pub async fn pull ( self : & Arc < Self > ) -> Result < ContentAndVerity < ObjectID > > {
196196 let ( _manifest_digest, raw_manifest) = self
197197 . proxy
198198 . fetch_manifest_raw_oci ( & self . img )
@@ -213,11 +213,11 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
213213/// Pull the target image, and add the provided tag. If this is a mountable
214214/// image (i.e. not an artifact), it is *not* unpacked by default.
215215pub async fn pull (
216- repo : & Repository < impl FsVerityHashValue > ,
216+ repo : & Arc < Repository < impl FsVerityHashValue > > ,
217217 imgref : & str ,
218218 reference : Option < & str > ,
219219) -> Result < ( ) > {
220- let op = ImageOp :: new ( repo, imgref) . await ?;
220+ let op = Arc :: new ( ImageOp :: new ( repo, imgref) . await ?) ;
221221 let ( sha256, id) = op
222222 . pull ( )
223223 . await
@@ -280,7 +280,7 @@ pub fn open_config_shallow<ObjectID: FsVerityHashValue>(
280280}
281281
282282pub fn write_config < ObjectID : FsVerityHashValue > (
283- repo : & Repository < ObjectID > ,
283+ repo : & Arc < Repository < ObjectID > > ,
284284 config : & ImageConfiguration ,
285285 refs : DigestMap < ObjectID > ,
286286) -> Result < ContentAndVerity < ObjectID > > {
@@ -294,7 +294,7 @@ pub fn write_config<ObjectID: FsVerityHashValue>(
294294}
295295
296296pub fn seal < ObjectID : FsVerityHashValue > (
297- repo : & Repository < ObjectID > ,
297+ repo : & Arc < Repository < ObjectID > > ,
298298 name : & str ,
299299 verity : Option < & ObjectID > ,
300300) -> Result < ContentAndVerity < ObjectID > > {
@@ -421,7 +421,7 @@ mod test {
421421 let layer_id: [ u8 ; 32 ] = context. finalize ( ) . into ( ) ;
422422
423423 let repo_dir = tempdir ( ) ;
424- let repo = Repository :: < Sha256HashValue > :: open_path ( CWD , & repo_dir) . unwrap ( ) ;
424+ let repo = Arc :: new ( Repository :: < Sha256HashValue > :: open_path ( CWD , & repo_dir) . unwrap ( ) ) ;
425425 let id = import_layer ( & repo, & layer_id, Some ( "name" ) , & mut layer. as_slice ( ) ) . unwrap ( ) ;
426426
427427 let mut dump = String :: new ( ) ;
0 commit comments