@@ -2,14 +2,14 @@ use std::path::{Path, PathBuf};
22use std:: sync:: Arc ;
33
44use anyhow:: { Context , Result } ;
5+ use oci_distribution:: config:: { Architecture , Config as DistConfig , ConfigFile , Os } ;
56use oci_distribution:: {
67 client,
78 client:: { ClientProtocol , Config , ImageLayer } ,
89 manifest:: OciImageManifest ,
9- Reference ,
1010 secrets:: RegistryAuth ,
11+ Reference ,
1112} ;
12- use oci_distribution:: config:: { Architecture , ConfigFile , Config as DistConfig , Os } ;
1313use serde_json;
1414use tokio:: fs:: File ;
1515use tokio:: io:: { AsyncReadExt , AsyncWriteExt } ;
@@ -20,8 +20,7 @@ use tokio::task::block_in_place;
2020use warg_crypto:: hash:: AnyHash ;
2121
2222use crate :: {
23- contentstore:: ContentStoreError ,
24- contentstore:: ContentStoreError :: ContentStoreInternalError ,
23+ contentstore:: ContentStoreError , contentstore:: ContentStoreError :: ContentStoreInternalError ,
2524} ;
2625
2726const COMPONENT_ARTIFACT_TYPE : & str = "application/vnd.bytecodealliance.component.v1+wasm" ;
@@ -52,7 +51,10 @@ impl Client {
5251 digest : & AnyHash ,
5352 ) -> Result < File , ContentStoreError > {
5453 let path = self . cached_content_path ( digest) ;
55- if Path :: new ( & path) . try_exists ( ) . map_err ( |e| ContentStoreError :: ContentStoreInternalError ( e. to_string ( ) ) ) ? {
54+ if Path :: new ( & path)
55+ . try_exists ( )
56+ . map_err ( |e| ContentStoreError :: ContentStoreInternalError ( e. to_string ( ) ) ) ?
57+ {
5658 let file = File :: open ( path)
5759 . await
5860 . map_err ( |e| ContentStoreError :: ContentStoreInternalError ( e. to_string ( ) ) ) ?;
@@ -69,18 +71,13 @@ impl Client {
6971 // block_on.
7072 let result = block_in_place ( || {
7173 Handle :: current ( ) . block_on ( async move {
72- let mut oci = self
73- . oci_client
74- . write ( )
75- . await ;
76- oci
77- . pull ( & reference, & self . auth , vec ! [ WASM_LAYER_MEDIA_TYPE ] )
74+ let mut oci = self . oci_client . write ( ) . await ;
75+ oci. pull ( & reference, & self . auth , vec ! [ WASM_LAYER_MEDIA_TYPE ] )
7876 . await
7977 } )
8078 } ) ;
8179
82- let image = result
83- . map_err ( |e| ContentStoreInternalError ( e. to_string ( ) ) ) ?;
80+ let image = result. map_err ( |e| ContentStoreInternalError ( e. to_string ( ) ) ) ?;
8481
8582 let layer = image
8683 . layers
@@ -90,8 +87,7 @@ impl Client {
9087 let mut file = File :: create ( self . cached_content_path ( digest) )
9188 . await
9289 . map_err ( |e| ContentStoreInternalError ( e. to_string ( ) ) ) ?;
93- file
94- . write_all ( & layer. data )
90+ file. write_all ( & layer. data )
9591 . await
9692 . map_err ( |e| ContentStoreInternalError ( e. to_string ( ) ) ) ?;
9793 Ok ( file)
@@ -121,8 +117,8 @@ impl Client {
121117 } ) ,
122118 ..Default :: default ( )
123119 } ;
124- let config_data = serde_json :: to_vec ( & config )
125- . map_err ( |e| ContentStoreInternalError ( e. to_string ( ) ) ) ?;
120+ let config_data =
121+ serde_json :: to_vec ( & config ) . map_err ( |e| ContentStoreInternalError ( e. to_string ( ) ) ) ?;
126122 let oci_config = Config :: oci_v1 ( config_data, None ) ;
127123 let mut layers = Vec :: new ( ) ;
128124 let wasm_layer = Self :: wasm_layer ( file)
@@ -135,15 +131,11 @@ impl Client {
135131
136132 // TODO: fix the higher-level lifetime error that occurs when not using block_in_place and
137133 // block_on.
138- let result= block_in_place ( || {
134+ let result = block_in_place ( || {
139135 Handle :: current ( ) . block_on ( async move {
140136 tracing:: log:: trace!( "Pushing component to {:?}" , reference) ;
141- let mut oci = self
142- . oci_client
143- . write ( )
144- . await ;
145- oci
146- . push ( & reference, & layers, oci_config, & self . auth , Some ( manifest) )
137+ let mut oci = self . oci_client . write ( ) . await ;
138+ oci. push ( & reference, & layers, oci_config, & self . auth , Some ( manifest) )
147139 . await
148140 } )
149141 } ) ;
@@ -154,7 +146,10 @@ impl Client {
154146 . map_err ( |e| ContentStoreInternalError ( e. to_string ( ) ) )
155147 }
156148
157- pub async fn content_exists ( & self , reference : impl AsRef < str > ) -> Result < bool , ContentStoreError > {
149+ pub async fn content_exists (
150+ & self ,
151+ reference : impl AsRef < str > ,
152+ ) -> Result < bool , ContentStoreError > {
158153 let reference: Reference = reference
159154 . as_ref ( )
160155 . parse ( )
@@ -163,10 +158,7 @@ impl Client {
163158 . unwrap ( ) ;
164159
165160 let mut oci = self . oci_client . write ( ) . await ;
166- match oci
167- . fetch_manifest_digest ( & reference, & self . auth )
168- . await
169- {
161+ match oci. fetch_manifest_digest ( & reference, & self . auth ) . await {
170162 Ok ( _) => Ok ( true ) ,
171163 Err ( _) => Ok ( false ) ,
172164 }
@@ -177,7 +169,9 @@ impl Client {
177169 tracing:: log:: trace!( "Reading wasm component from {:?}" , file) ;
178170
179171 let mut contents = vec ! [ ] ;
180- file. read_to_end ( & mut contents) . await . context ( "cannot read wasm component" ) ?;
172+ file. read_to_end ( & mut contents)
173+ . await
174+ . context ( "cannot read wasm component" ) ?;
181175
182176 Ok ( ImageLayer :: new (
183177 contents,
0 commit comments