1+ //! Storage backends for registry data.
2+
13use crate :: config:: StorageBackend ;
24use crate :: error:: { RegistryError , Result } ;
35use async_trait:: async_trait;
@@ -7,23 +9,35 @@ use std::sync::Arc;
79use tokio:: fs;
810use tokio:: sync:: RwLock ;
911
12+ /// Container image manifest with metadata.
1013#[ derive( Clone ) ]
1114pub struct ManifestEntry {
15+ /// Raw manifest data.
1216 pub data : Vec < u8 > ,
17+ /// Content type of the manifest.
1318 pub content_type : String ,
1419}
1520
21+ /// Trait for storage backends handling registry data.
1622#[ async_trait]
1723pub trait Storage : Send + Sync {
24+ /// Stores a manifest with the given key.
1825 async fn store_manifest ( & self , key : String , entry : ManifestEntry ) -> Result < ( ) > ;
26+ /// Retrieves a manifest by key.
1927 async fn get_manifest ( & self , key : & str ) -> Result < Option < ManifestEntry > > ;
28+ /// Stores a blob with the given digest.
2029 async fn store_blob ( & self , digest : String , data : Vec < u8 > ) -> Result < ( ) > ;
30+ /// Retrieves a blob by digest.
2131 async fn get_blob ( & self , digest : & str ) -> Result < Option < Vec < u8 > > > ;
32+ /// Creates a new upload session with the given UUID.
2233 async fn create_upload ( & self , uuid : String ) -> Result < ( ) > ;
34+ /// Appends data to an existing upload session.
2335 async fn append_upload ( & self , uuid : & str , data : & [ u8 ] ) -> Result < ( ) > ;
36+ /// Finalizes an upload session and returns the complete data.
2437 async fn finish_upload ( & self , uuid : & str ) -> Result < Option < Vec < u8 > > > ;
2538}
2639
40+ /// In-memory storage implementation.
2741#[ derive( Default ) ]
2842pub struct MemoryStorage {
2943 manifests : Arc < RwLock < HashMap < String , ManifestEntry > > > ,
@@ -32,6 +46,7 @@ pub struct MemoryStorage {
3246}
3347
3448impl MemoryStorage {
49+ /// Creates a new in-memory storage backend.
3550 pub fn new ( ) -> Self {
3651 Self :: default ( )
3752 }
@@ -76,12 +91,14 @@ impl Storage for MemoryStorage {
7691 }
7792}
7893
94+ /// Disk-based storage implementation.
7995pub struct DiskStorage {
8096 base_path : PathBuf ,
8197 _temp_dir : Option < tempfile:: TempDir > ,
8298}
8399
84100impl DiskStorage {
101+ /// Creates a new disk storage backend at the specified path.
85102 pub async fn new ( path : PathBuf ) -> Result < Self > {
86103 fs:: create_dir_all ( & path) . await ?;
87104 fs:: create_dir_all ( path. join ( "manifests" ) ) . await ?;
@@ -94,6 +111,7 @@ impl DiskStorage {
94111 } )
95112 }
96113
114+ /// Creates a new temporary disk storage backend.
97115 pub async fn temp ( ) -> Result < Self > {
98116 let temp_dir = tempfile:: tempdir ( ) ?;
99117 let path = temp_dir. path ( ) . to_path_buf ( ) ;
@@ -211,6 +229,7 @@ impl Storage for DiskStorage {
211229 }
212230}
213231
232+ /// Creates a storage backend from the given configuration.
214233pub async fn create_storage ( backend : & StorageBackend ) -> Result < Arc < dyn Storage > > {
215234 match backend {
216235 StorageBackend :: Memory => Ok ( Arc :: new ( MemoryStorage :: new ( ) ) ) ,
0 commit comments