@@ -3,7 +3,7 @@ use std::process::Command;
3
3
pub mod image;
4
4
pub mod tar;
5
5
6
- use std:: { collections:: HashMap , io:: Read , iter:: zip, path:: Path } ;
6
+ use std:: { collections:: HashMap , io:: Read , iter:: zip, path:: Path , sync :: Arc } ;
7
7
8
8
use anyhow:: { bail, ensure, Context , Result } ;
9
9
use async_compression:: tokio:: bufread:: { GzipDecoder , ZstdDecoder } ;
@@ -23,7 +23,7 @@ use crate::{
23
23
} ;
24
24
25
25
pub fn import_layer < ObjectID : FsVerityHashValue > (
26
- repo : & Repository < ObjectID > ,
26
+ repo : & Arc < Repository < ObjectID > > ,
27
27
sha256 : & Sha256Digest ,
28
28
name : Option < & str > ,
29
29
tar_stream : & mut impl Read ,
@@ -44,8 +44,8 @@ pub fn ls_layer<ObjectID: FsVerityHashValue>(
44
44
Ok ( ( ) )
45
45
}
46
46
47
- struct ImageOp < ' repo , ObjectID : FsVerityHashValue > {
48
- repo : & ' repo Repository < ObjectID > ,
47
+ struct ImageOp < ObjectID : FsVerityHashValue > {
48
+ repo : Arc < Repository < ObjectID > > ,
49
49
proxy : ImageProxy ,
50
50
img : OpenedImage ,
51
51
progress : MultiProgress ,
@@ -67,8 +67,8 @@ fn sha256_from_digest(digest: &str) -> Result<Sha256Digest> {
67
67
68
68
type ContentAndVerity < ObjectID > = ( Sha256Digest , ObjectID ) ;
69
69
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 > {
72
72
// See https://github.com/containers/skopeo/issues/2563
73
73
let skopeo_cmd = if imgref. starts_with ( "containers-storage:" ) {
74
74
let mut cmd = Command :: new ( "podman" ) ;
@@ -87,7 +87,7 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
87
87
let img = proxy. open_image ( imgref) . await . context ( "Opening image" ) ?;
88
88
let progress = MultiProgress :: new ( ) ;
89
89
Ok ( ImageOp {
90
- repo,
90
+ repo : Arc :: clone ( repo ) ,
91
91
proxy,
92
92
img,
93
93
progress,
@@ -142,7 +142,7 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
142
142
}
143
143
144
144
pub async fn ensure_config (
145
- & self ,
145
+ self : & Arc < Self > ,
146
146
manifest_layers : & [ Descriptor ] ,
147
147
descriptor : & Descriptor ,
148
148
) -> Result < ContentAndVerity < ObjectID > > {
@@ -192,7 +192,7 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
192
192
}
193
193
}
194
194
195
- pub async fn pull ( & self ) -> Result < ContentAndVerity < ObjectID > > {
195
+ pub async fn pull ( self : & Arc < Self > ) -> Result < ContentAndVerity < ObjectID > > {
196
196
let ( _manifest_digest, raw_manifest) = self
197
197
. proxy
198
198
. fetch_manifest_raw_oci ( & self . img )
@@ -213,11 +213,11 @@ impl<'repo, ObjectID: FsVerityHashValue> ImageOp<'repo, ObjectID> {
213
213
/// Pull the target image, and add the provided tag. If this is a mountable
214
214
/// image (i.e. not an artifact), it is *not* unpacked by default.
215
215
pub async fn pull (
216
- repo : & Repository < impl FsVerityHashValue > ,
216
+ repo : & Arc < Repository < impl FsVerityHashValue > > ,
217
217
imgref : & str ,
218
218
reference : Option < & str > ,
219
219
) -> Result < ( ) > {
220
- let op = ImageOp :: new ( repo, imgref) . await ?;
220
+ let op = Arc :: new ( ImageOp :: new ( repo, imgref) . await ?) ;
221
221
let ( sha256, id) = op
222
222
. pull ( )
223
223
. await
@@ -280,7 +280,7 @@ pub fn open_config_shallow<ObjectID: FsVerityHashValue>(
280
280
}
281
281
282
282
pub fn write_config < ObjectID : FsVerityHashValue > (
283
- repo : & Repository < ObjectID > ,
283
+ repo : & Arc < Repository < ObjectID > > ,
284
284
config : & ImageConfiguration ,
285
285
refs : DigestMap < ObjectID > ,
286
286
) -> Result < ContentAndVerity < ObjectID > > {
@@ -294,7 +294,7 @@ pub fn write_config<ObjectID: FsVerityHashValue>(
294
294
}
295
295
296
296
pub fn seal < ObjectID : FsVerityHashValue > (
297
- repo : & Repository < ObjectID > ,
297
+ repo : & Arc < Repository < ObjectID > > ,
298
298
name : & str ,
299
299
verity : Option < & ObjectID > ,
300
300
) -> Result < ContentAndVerity < ObjectID > > {
@@ -421,7 +421,7 @@ mod test {
421
421
let layer_id: [ u8 ; 32 ] = context. finalize ( ) . into ( ) ;
422
422
423
423
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 ( ) ) ;
425
425
let id = import_layer ( & repo, & layer_id, Some ( "name" ) , & mut layer. as_slice ( ) ) . unwrap ( ) ;
426
426
427
427
let mut dump = String :: new ( ) ;
0 commit comments