1
- use std:: { fs:: Permissions , os:: unix:: fs:: PermissionsExt , path:: Path } ;
1
+ use std:: {
2
+ borrow:: Cow , fs:: Permissions , mem:: MaybeUninit , os:: unix:: fs:: PermissionsExt , path:: Path ,
3
+ } ;
2
4
3
5
use ahash:: HashMap ;
4
6
use apt_auth_config:: { AuthConfig , Authenticator } ;
@@ -33,7 +35,7 @@ pub struct OmaSourceEntry<'a> {
33
35
from : OnceCell < OmaSourceEntryFrom > ,
34
36
}
35
37
36
- pub async fn sources_lists < ' a > (
38
+ pub async fn scan_sources_lists < ' a > (
37
39
sysroot : impl AsRef < Path > ,
38
40
arch : & ' a str ,
39
41
cb : & ' a impl AsyncFn ( Event ) ,
@@ -90,6 +92,22 @@ pub async fn sources_lists<'a>(
90
92
pub enum OmaSourceEntryFrom {
91
93
Http ,
92
94
Local ,
95
+ MirrorHttp ,
96
+ MirrorFile ,
97
+ }
98
+
99
+ #[ derive( Debug ) ]
100
+ pub struct MirrorTransportItem {
101
+ pub url : String ,
102
+ pub priority : i64 ,
103
+ pub archs : Vec < String > ,
104
+ pub item_type : MirrorTransportItemType ,
105
+ }
106
+
107
+ #[ derive( Debug ) ]
108
+ pub enum MirrorTransportItemType {
109
+ Index ,
110
+ Deb ,
93
111
}
94
112
95
113
impl < ' a > OmaSourceEntry < ' a > {
@@ -106,12 +124,29 @@ impl<'a> OmaSourceEntry<'a> {
106
124
107
125
pub fn from ( & self ) -> Result < & OmaSourceEntryFrom , RefreshError > {
108
126
self . from . get_or_try_init ( || {
109
- let url = Url :: parse ( self . url ( ) )
110
- . map_err ( |_| RefreshError :: InvalidUrl ( self . url ( ) . to_string ( ) ) ) ?;
127
+ let ( transport_type, url) = self
128
+ . url ( )
129
+ . split_once ( "+" )
130
+ . unwrap_or_else ( || ( "" , self . url ( ) ) ) ;
131
+
132
+ let url =
133
+ Url :: parse ( url) . map_err ( |_| RefreshError :: InvalidUrl ( self . url ( ) . to_string ( ) ) ) ?;
134
+
135
+ let schema = if !transport_type. is_empty ( ) {
136
+ let mut schema = "" . to_string ( ) ;
137
+ schema. push_str ( transport_type) ;
138
+ schema. push_str ( "+" ) ;
139
+ schema. push_str ( url. scheme ( ) ) ;
140
+ Cow :: Owned ( schema)
141
+ } else {
142
+ url. scheme ( ) . into ( )
143
+ } ;
111
144
112
- match url . scheme ( ) {
145
+ match schema . as_ref ( ) {
113
146
"file" => Ok ( OmaSourceEntryFrom :: Local ) ,
114
147
"http" | "https" => Ok ( OmaSourceEntryFrom :: Http ) ,
148
+ "mirror" | "mirror+http" | "mirror+https" => Ok ( OmaSourceEntryFrom :: MirrorHttp ) ,
149
+ "mirror+files" => Ok ( OmaSourceEntryFrom :: MirrorFile ) ,
115
150
x => Err ( RefreshError :: UnsupportedProtocol ( x. to_string ( ) ) ) ,
116
151
}
117
152
} )
@@ -285,6 +320,17 @@ impl MirrorSource<'_, '_> {
285
320
self . fetch_local_release ( replacer, index, total, download_dir, callback)
286
321
. await
287
322
}
323
+ OmaSourceEntryFrom :: MirrorHttp => todo ! ( ) ,
324
+ OmaSourceEntryFrom :: MirrorFile => {
325
+ let path = self . dist_path ( ) . strip_prefix ( "mirror+file:" ) . unwrap ( ) ;
326
+ let f = fs:: read_to_string ( path)
327
+ . await
328
+ . map_err ( |e| RefreshError :: FailedToOperateDirOrFile ( path. to_string ( ) , e) ) ?;
329
+
330
+ let items = parse_mirror_transport_file ( & f) ;
331
+
332
+ todo ! ( )
333
+ }
288
334
}
289
335
}
290
336
@@ -550,6 +596,45 @@ impl MirrorSource<'_, '_> {
550
596
}
551
597
}
552
598
599
+ fn parse_mirror_transport_file ( f : & str ) -> Vec < MirrorTransportItem > {
600
+ let mut res = vec ! [ ] ;
601
+
602
+ for i in f. lines ( ) {
603
+ let mut line = i. split_ascii_whitespace ( ) ;
604
+ let url = line. next ( ) . expect ( "File contains illegal item" ) ;
605
+ let mut priority = 0 ;
606
+ let mut archs = vec ! [ ] ;
607
+ let mut item_type = MirrorTransportItemType :: Deb ;
608
+
609
+ while let Some ( entry) = line. next ( ) {
610
+ match entry. split_once ( ':' ) {
611
+ Some ( ( k, v) ) => match k {
612
+ "priority" => priority = v. parse :: < i64 > ( ) . expect ( "Failed to parse priority" ) ,
613
+ "arch" => archs. push ( v. to_string ( ) ) ,
614
+ "type" => {
615
+ item_type = match v {
616
+ "deb" => MirrorTransportItemType :: Deb ,
617
+ "index" => MirrorTransportItemType :: Index ,
618
+ x => panic ! ( "Failed to parse type: {x}" ) ,
619
+ }
620
+ }
621
+ x => panic ! ( "Failed to parse key: {x}" ) ,
622
+ } ,
623
+ None => panic ! ( "File contains illegal item" ) ,
624
+ }
625
+ }
626
+
627
+ res. push ( MirrorTransportItem {
628
+ url : url. to_string ( ) ,
629
+ archs,
630
+ priority,
631
+ item_type,
632
+ } ) ;
633
+ }
634
+
635
+ res
636
+ }
637
+
553
638
impl < ' a , ' b > MirrorSources < ' a , ' b > {
554
639
pub fn from_sourcelist (
555
640
sourcelist : & ' a [ OmaSourceEntry < ' a > ] ,
0 commit comments