11use std:: fs:: { self , File } ;
2- use std:: io:: { Read , Write } ;
32use std:: path:: { Path , PathBuf } ;
43use miette:: { miette, IntoDiagnostic , Result , Context } ;
54use owo_colors:: OwoColorize ;
65use sha2:: { Digest , Sha256 } ;
76use flate2:: read:: GzDecoder ;
87use serde_json:: Value ;
9- use ureq:: { Agent , AgentBuilder } ;
8+ use ureq:: AgentBuilder ;
109
1110use crate :: container:: HACKEROS_LIB ;
1211
1312pub struct ImageManager ;
1413
1514impl ImageManager {
16- /// Pobiera warstwy obrazu. Jeśli nie ma go lokalnie, ściąga z rejestru.
1715 pub fn resolve_image_layers ( image_ref : & str ) -> Result < Vec < PathBuf > > {
1816 let ( registry, repo, tag) = parse_image_ref ( image_ref) ;
1917 let safe_name = format ! ( "{}_{}_{}" , registry. replace( "/" , "_" ) , repo. replace( "/" , "_" ) , tag) ;
@@ -27,7 +25,6 @@ impl ImageManager {
2725 Self :: pull_image ( & registry, & repo, & tag, & image_dir)
2826 }
2927
30- /// Pobiera obraz z rejestru i zapisuje warstwy.
3128 fn pull_image ( registry : & str , repo : & str , tag : & str , dest_dir : & Path ) -> Result < Vec < PathBuf > > {
3229 fs:: create_dir_all ( dest_dir) . into_diagnostic ( ) ?;
3330
@@ -44,7 +41,6 @@ impl ImageManager {
4441
4542 let manifest_json: Value = resp. into_json ( ) . into_diagnostic ( ) ?;
4643
47- // Obsługa manifest list (multi‑arch) oraz pojedynczego manifestu
4844 let ( layers, config_digest) = if let Some ( manifests) = manifest_json[ "manifests" ] . as_array ( ) {
4945 let arch = std:: env:: consts:: ARCH ;
5046 let os = std:: env:: consts:: OS ;
@@ -88,12 +84,10 @@ impl ImageManager {
8884 ( layers, config_digest)
8985 } ;
9086
91- // Pobierz plik konfiguracyjny (opcjonalny)
9287 if !config_digest. is_empty ( ) {
9388 download_config ( registry, repo, & token, & config_digest, dest_dir) ?;
9489 }
9590
96- // Pobierz i rozpakuj warstwy
9791 let layers_dir = PathBuf :: from ( format ! ( "{}/layers" , HACKEROS_LIB ) ) ;
9892 fs:: create_dir_all ( & layers_dir) . into_diagnostic ( ) ?;
9993
@@ -107,7 +101,6 @@ impl ImageManager {
107101 layer_paths. push ( layer_path) ;
108102 }
109103
110- // Zapisz manifest (listę ścieżek warstw) w katalogu obrazu
111104 let manifest_path = dest_dir. join ( "layers.json" ) ;
112105 let paths_str: Vec < String > = layer_paths
113106 . iter ( )
@@ -117,7 +110,6 @@ impl ImageManager {
117110 . into_diagnostic ( )
118111 . wrap_err ( "Failed to write layers.json" ) ?;
119112
120- // Skopiuj plik konfiguracyjny (jeśli istnieje) do katalogu obrazu
121113 if !config_digest. is_empty ( ) {
122114 let config_path = dest_dir. join ( "config.json" ) ;
123115 let config_file = dest_dir. join ( format ! ( "{}.json" , config_digest. replace( "sha256:" , "" ) ) ) ;
@@ -129,7 +121,6 @@ impl ImageManager {
129121 Ok ( layer_paths)
130122 }
131123
132- /// Importuje obraz z archiwum tar (legacy).
133124 pub fn import_tar ( path : & Path , name : & str ) -> Result < ( ) > {
134125 println ! ( "{} Importing legacy tarball {}..." , "[IMPORT]" . bold( ) . yellow( ) , name) ;
135126 let safe_name = name. replace ( ":" , "_" ) ;
@@ -149,10 +140,6 @@ impl ImageManager {
149140 }
150141}
151142
152- // ------------------------------------------------------------
153- // Funkcje pomocnicze
154- // ------------------------------------------------------------
155-
156143fn parse_image_ref ( r : & str ) -> ( String , String , String ) {
157144 let parts: Vec < & str > = r. split ( '/' ) . collect ( ) ;
158145 let registry: String ;
@@ -234,7 +221,6 @@ fn download_and_extract_layer(
234221 std:: io:: copy ( & mut reader, & mut f) . into_diagnostic ( ) ?;
235222 }
236223
237- // Weryfikacja sumy kontrolnej
238224 let mut hasher = Sha256 :: new ( ) ;
239225 let mut file = File :: open ( & tmp_tar) . into_diagnostic ( ) ?;
240226 std:: io:: copy ( & mut file, & mut hasher) . into_diagnostic ( ) ?;
0 commit comments