5
5
//! pre-pulled (and in the future, pinned) before a new image root
6
6
//! is considered ready.
7
7
8
+ use std:: num:: NonZeroUsize ;
9
+
8
10
use anyhow:: { Context , Result } ;
9
11
use camino:: Utf8Path ;
10
12
use cap_std_ext:: cap_std:: fs:: Dir ;
@@ -145,16 +147,22 @@ fn parse_container_file(file_contents: &tini::Ini) -> Result<BoundImage> {
145
147
#[ context( "Pulling bound images" ) ]
146
148
pub ( crate ) async fn pull_images ( sysroot : & Storage , bound_images : Vec < BoundImage > ) -> Result < ( ) > {
147
149
tracing:: debug!( "Pulling bound images: {}" , bound_images. len( ) ) ;
148
- // Only initialize the image storage if we have images to pull
149
- let imgstore = if !bound_images . is_empty ( ) {
150
- sysroot . get_ensure_imgstore ( ) ?
151
- } else {
150
+ // Yes, the usage of NonZeroUsize here is...maybe odd looking, but I find
151
+ // it an elegant way to divide (empty vector, non empty vector) since
152
+ // we want to print the length too below.
153
+ let Some ( n ) = NonZeroUsize :: new ( bound_images . len ( ) ) else {
152
154
return Ok ( ( ) ) ;
153
155
} ;
154
- //TODO: do this in parallel
156
+ // Only do work like initializing the image storage if we have images to pull.
157
+ let imgstore = sysroot. get_ensure_imgstore ( ) ?;
158
+ // TODO: do this in parallel
155
159
for bound_image in bound_images {
156
160
let image = & bound_image. image ;
157
- let desc = format ! ( "Updating bound image: {image}" ) ;
161
+ if imgstore. exists ( image) . await ? {
162
+ tracing:: debug!( "Bound image already present: {image}" ) ;
163
+ continue ;
164
+ }
165
+ let desc = format ! ( "Fetching bound image: {image}" ) ;
158
166
crate :: utils:: async_task_with_spinner ( & desc, async move {
159
167
imgstore
160
168
. pull ( & bound_image. image , PullMode :: IfNotExists )
@@ -163,6 +171,8 @@ pub(crate) async fn pull_images(sysroot: &Storage, bound_images: Vec<BoundImage>
163
171
. await ?;
164
172
}
165
173
174
+ println ! ( "Bound images stored: {n}" ) ;
175
+
166
176
Ok ( ( ) )
167
177
}
168
178
0 commit comments