@@ -19,15 +19,28 @@ pub static PKG_URL: &str = "https://launchpad.net/ubuntu/+archive/primary/+files
1919pub type Result < T > = std:: result:: Result < T , Error > ;
2020
2121/// Helper function that decides whether the tar file `entry` matches
22- /// `file_name`
23- fn tar_entry_matches < R : Read > ( entry : & std:: io:: Result < tar:: Entry < R > > , file_name : & str ) -> bool {
24- match entry {
25- Ok ( entry) => match entry. path ( ) {
26- Ok ( path) => path. file_name ( ) == Some ( file_name. as_ref ( ) ) ,
27- Err ( _) => false ,
28- } ,
29- Err ( _) => false ,
22+ /// one of the `file_names`
23+ fn tar_entry_matches_any < R : Read > (
24+ entry : & std:: io:: Result < tar:: Entry < R > > ,
25+ file_names : & [ & str ] ,
26+ ) -> bool {
27+ let Ok ( entry) = entry else { return false } ;
28+ let Ok ( path) = entry. path ( ) else { return false } ;
29+
30+ let res = path
31+ . file_name ( )
32+ . and_then ( |name| name. to_str ( ) )
33+ . map ( |name| file_names. contains ( & name) )
34+ . unwrap_or ( false ) ;
35+ if res {
36+ println ! (
37+ "{}" ,
38+ format!( "Found matching file: {}" , path. display( ) )
39+ . bold( )
40+ . green( )
41+ ) ;
3042 }
43+ res
3144}
3245
3346#[ derive( Debug , Snafu ) ]
@@ -96,7 +109,7 @@ fn request_ubuntu_pkg(deb_file_name: &str) -> Result<reqwest::blocking::Response
96109/// extract the file.
97110pub fn write_ubuntu_pkg_file < P : AsRef < Path > > (
98111 deb_file_name : & str ,
99- file_name : & str ,
112+ file_names : & [ & str ] ,
100113 out_path : P ,
101114) -> Result < ( ) > {
102115 let out_path = out_path. as_ref ( ) ;
@@ -122,15 +135,15 @@ pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
122135 match ext {
123136 b"gz" => {
124137 let data = GzDecoder :: new ( entry) ;
125- write_ubuntu_data_tar_file ( data, file_name , out_path)
138+ write_ubuntu_data_tar_file ( data, file_names , out_path)
126139 }
127140 b"xz" => {
128141 let data = LzmaReader :: new_decompressor ( entry) . context ( DataUnzipLzmaSnafu ) ?;
129- write_ubuntu_data_tar_file ( data, file_name , out_path)
142+ write_ubuntu_data_tar_file ( data, file_names , out_path)
130143 }
131144 b"zst" => {
132145 let data = zstd:: stream:: read:: Decoder :: new ( entry) . context ( DataUnzipZstdSnafu ) ?;
133- write_ubuntu_data_tar_file ( data, file_name , out_path)
146+ write_ubuntu_data_tar_file ( data, file_names , out_path)
134147 }
135148 ext => None . context ( DataExtSnafu { ext } ) ,
136149 } ?;
@@ -145,14 +158,14 @@ pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
145158/// and extract the file.
146159fn write_ubuntu_data_tar_file < R : Read > (
147160 data_tar_bytes : R ,
148- file_name : & str ,
161+ file_names : & [ & str ] ,
149162 out_path : & Path ,
150163) -> Result < ( ) > {
151164 let mut data_tar = tar:: Archive :: new ( data_tar_bytes) ;
152165 let mut entry = data_tar
153166 . entries ( )
154167 . context ( DataEntriesSnafu ) ?
155- . find ( |entry| tar_entry_matches ( entry, file_name ) )
168+ . find ( |entry| tar_entry_matches_any ( entry, file_names ) )
156169 . context ( FileNotFoundSnafu ) ?
157170 . context ( ReadSnafu ) ?;
158171 let mut out_file = File :: create ( out_path) . context ( CreateSnafu ) ?;
0 commit comments