@@ -63,8 +63,10 @@ fn parse_spec_dir(root: &Dir, spec_dir: &str) -> Result<Vec<BoundImage>> {
63
63
let file_ini = tini:: Ini :: from_string ( & file_contents) . context ( "Parse to ini" ) ?;
64
64
let file_extension = Utf8Path :: new ( file_name) . extension ( ) ;
65
65
let bound_image = match file_extension {
66
- Some ( "image" ) => parse_image_file ( file_name, & file_ini) ,
67
- Some ( "container" ) => parse_container_file ( file_name, & file_ini) ,
66
+ Some ( "image" ) => parse_image_file ( & file_ini) . with_context ( || format ! ( "Parsing {path}" ) ) ,
67
+ Some ( "container" ) => {
68
+ parse_container_file ( & file_ini) . with_context ( || format ! ( "Parsing {path}" ) )
69
+ }
68
70
_ => anyhow:: bail!( "Invalid file extension: {file_name}" ) ,
69
71
} ?;
70
72
@@ -74,11 +76,10 @@ fn parse_spec_dir(root: &Dir, spec_dir: &str) -> Result<Vec<BoundImage>> {
74
76
Ok ( bound_images)
75
77
}
76
78
77
- #[ context( "parse image file {file_name}" ) ]
78
- fn parse_image_file ( file_name : & str , file_contents : & tini:: Ini ) -> Result < BoundImage > {
79
+ fn parse_image_file ( file_contents : & tini:: Ini ) -> Result < BoundImage > {
79
80
let image: String = file_contents
80
81
. get ( "Image" , "Image" )
81
- . ok_or_else ( || anyhow:: anyhow!( "Missing Image field in {file_name} " ) ) ?;
82
+ . ok_or_else ( || anyhow:: anyhow!( "Missing Image field" ) ) ?;
82
83
83
84
//TODO: auth_files have some semi-complicated edge cases that we need to handle,
84
85
// so for now let's bail out if we see one since the existence of an authfile
@@ -92,11 +93,10 @@ fn parse_image_file(file_name: &str, file_contents: &tini::Ini) -> Result<BoundI
92
93
Ok ( bound_image)
93
94
}
94
95
95
- #[ context( "parse container file {file_name}" ) ]
96
- fn parse_container_file ( file_name : & str , file_contents : & tini:: Ini ) -> Result < BoundImage > {
96
+ fn parse_container_file ( file_contents : & tini:: Ini ) -> Result < BoundImage > {
97
97
let image: String = file_contents
98
98
. get ( "Container" , "Image" )
99
- . ok_or_else ( || anyhow:: anyhow!( "Missing Image field in {file_name} " ) ) ?;
99
+ . ok_or_else ( || anyhow:: anyhow!( "Missing Image field" ) ) ?;
100
100
101
101
let bound_image = BoundImage :: new ( image. to_string ( ) , None ) ?;
102
102
Ok ( bound_image)
@@ -286,7 +286,7 @@ mod tests {
286
286
//should return BoundImage when no auth_file is present
287
287
let file_contents =
288
288
tini:: Ini :: from_string ( "[Image]\n Image=quay.io/foo/foo:latest" ) . unwrap ( ) ;
289
- let bound_image = parse_image_file ( "foo.image" , & file_contents) . unwrap ( ) ;
289
+ let bound_image = parse_image_file ( & file_contents) . unwrap ( ) ;
290
290
assert_eq ! ( bound_image. image, "quay.io/foo/foo:latest" ) ;
291
291
assert_eq ! ( bound_image. auth_file, None ) ;
292
292
@@ -295,11 +295,11 @@ mod tests {
295
295
"[Image]\n Image=quay.io/foo/foo:latest\n AuthFile=/etc/containers/auth.json" ,
296
296
)
297
297
. unwrap ( ) ;
298
- assert ! ( parse_image_file( "foo.image" , & file_contents) . is_err( ) ) ;
298
+ assert ! ( parse_image_file( & file_contents) . is_err( ) ) ;
299
299
300
300
//should return error when missing image field
301
301
let file_contents = tini:: Ini :: from_string ( "[Image]\n " ) . unwrap ( ) ;
302
- assert ! ( parse_image_file( "foo.image" , & file_contents) . is_err( ) ) ;
302
+ assert ! ( parse_image_file( & file_contents) . is_err( ) ) ;
303
303
304
304
Ok ( ( ) )
305
305
}
@@ -309,13 +309,13 @@ mod tests {
309
309
//should return BoundImage
310
310
let file_contents =
311
311
tini:: Ini :: from_string ( "[Container]\n Image=quay.io/foo/foo:latest" ) . unwrap ( ) ;
312
- let bound_image = parse_container_file ( "foo.container" , & file_contents) . unwrap ( ) ;
312
+ let bound_image = parse_container_file ( & file_contents) . unwrap ( ) ;
313
313
assert_eq ! ( bound_image. image, "quay.io/foo/foo:latest" ) ;
314
314
assert_eq ! ( bound_image. auth_file, None ) ;
315
315
316
316
//should return error when missing image field
317
317
let file_contents = tini:: Ini :: from_string ( "[Container]\n " ) . unwrap ( ) ;
318
- assert ! ( parse_container_file( "foo.container" , & file_contents) . is_err( ) ) ;
318
+ assert ! ( parse_container_file( & file_contents) . is_err( ) ) ;
319
319
320
320
Ok ( ( ) )
321
321
}
0 commit comments