1- use crate :: error:: { RegistryError , Result } ;
21use crate :: config:: StorageBackend ;
2+ use crate :: error:: { RegistryError , Result } ;
33use async_trait:: async_trait;
44use std:: collections:: HashMap ;
55use std:: path:: PathBuf ;
@@ -87,7 +87,7 @@ impl DiskStorage {
8787 fs:: create_dir_all ( path. join ( "manifests" ) ) . await ?;
8888 fs:: create_dir_all ( path. join ( "blobs" ) ) . await ?;
8989 fs:: create_dir_all ( path. join ( "uploads" ) ) . await ?;
90-
90+
9191 Ok ( Self {
9292 base_path : path,
9393 _temp_dir : None ,
@@ -97,11 +97,11 @@ impl DiskStorage {
9797 pub async fn temp ( ) -> Result < Self > {
9898 let temp_dir = tempfile:: tempdir ( ) ?;
9999 let path = temp_dir. path ( ) . to_path_buf ( ) ;
100-
100+
101101 fs:: create_dir_all ( path. join ( "manifests" ) ) . await ?;
102102 fs:: create_dir_all ( path. join ( "blobs" ) ) . await ?;
103103 fs:: create_dir_all ( path. join ( "uploads" ) ) . await ?;
104-
104+
105105 Ok ( Self {
106106 base_path : path,
107107 _temp_dir : Some ( temp_dir) ,
@@ -110,12 +110,16 @@ impl DiskStorage {
110110
111111 fn manifest_path ( & self , key : & str ) -> PathBuf {
112112 let safe_key = key. replace ( [ '/' , ':' ] , "_" ) ;
113- self . base_path . join ( "manifests" ) . join ( format ! ( "{}.json" , safe_key) )
113+ self . base_path
114+ . join ( "manifests" )
115+ . join ( format ! ( "{}.json" , safe_key) )
114116 }
115117
116118 fn manifest_meta_path ( & self , key : & str ) -> PathBuf {
117119 let safe_key = key. replace ( [ '/' , ':' ] , "_" ) ;
118- self . base_path . join ( "manifests" ) . join ( format ! ( "{}.meta" , safe_key) )
120+ self . base_path
121+ . join ( "manifests" )
122+ . join ( format ! ( "{}.meta" , safe_key) )
119123 }
120124
121125 fn blob_path ( & self , digest : & str ) -> PathBuf {
@@ -133,25 +137,26 @@ impl Storage for DiskStorage {
133137 async fn store_manifest ( & self , key : String , entry : ManifestEntry ) -> Result < ( ) > {
134138 let manifest_path = self . manifest_path ( & key) ;
135139 let meta_path = self . manifest_meta_path ( & key) ;
136-
140+
137141 fs:: write ( & manifest_path, & entry. data ) . await ?;
138142 fs:: write ( & meta_path, & entry. content_type ) . await ?;
139-
143+
140144 Ok ( ( ) )
141145 }
142146
143147 async fn get_manifest ( & self , key : & str ) -> Result < Option < ManifestEntry > > {
144148 let manifest_path = self . manifest_path ( key) ;
145149 let meta_path = self . manifest_meta_path ( key) ;
146-
150+
147151 if !manifest_path. exists ( ) {
148152 return Ok ( None ) ;
149153 }
150-
154+
151155 let data = fs:: read ( & manifest_path) . await ?;
152- let content_type = fs:: read_to_string ( & meta_path) . await
156+ let content_type = fs:: read_to_string ( & meta_path)
157+ . await
153158 . unwrap_or_else ( |_| "application/vnd.docker.distribution.manifest.v2+json" . to_string ( ) ) ;
154-
159+
155160 Ok ( Some ( ManifestEntry { data, content_type } ) )
156161 }
157162
@@ -163,11 +168,11 @@ impl Storage for DiskStorage {
163168
164169 async fn get_blob ( & self , digest : & str ) -> Result < Option < Vec < u8 > > > {
165170 let blob_path = self . blob_path ( digest) ;
166-
171+
167172 if !blob_path. exists ( ) {
168173 return Ok ( None ) ;
169174 }
170-
175+
171176 let data = fs:: read ( & blob_path) . await ?;
172177 Ok ( Some ( data) )
173178 }
@@ -180,28 +185,28 @@ impl Storage for DiskStorage {
180185
181186 async fn append_upload ( & self , uuid : & str , data : & [ u8 ] ) -> Result < ( ) > {
182187 let upload_path = self . upload_path ( uuid) ;
183-
188+
184189 if !upload_path. exists ( ) {
185190 return Err ( RegistryError :: UploadNotFound ( uuid. to_string ( ) ) ) ;
186191 }
187-
192+
188193 let mut existing = fs:: read ( & upload_path) . await ?;
189194 existing. extend_from_slice ( data) ;
190195 fs:: write ( & upload_path, & existing) . await ?;
191-
196+
192197 Ok ( ( ) )
193198 }
194199
195200 async fn finish_upload ( & self , uuid : & str ) -> Result < Option < Vec < u8 > > > {
196201 let upload_path = self . upload_path ( uuid) ;
197-
202+
198203 if !upload_path. exists ( ) {
199204 return Ok ( None ) ;
200205 }
201-
206+
202207 let data = fs:: read ( & upload_path) . await ?;
203208 fs:: remove_file ( & upload_path) . await ?;
204-
209+
205210 Ok ( Some ( data) )
206211 }
207212}
0 commit comments