@@ -3,19 +3,20 @@ pub mod logger;
33pub mod processor;
44pub mod progress;
55
6- use std:: process:: exit;
7- use std:: { fs, io:: ErrorKind } ;
8- #[ cfg( feature = "ui" ) ]
9- use tauri:: { AppHandle , Emitter } ;
106pub use args:: CmdArgs ;
117pub use logger:: Logger ;
128pub use processor:: Processor ;
139pub use progress:: Progress ;
10+ use std:: path:: Path ;
11+ use std:: process:: exit;
12+ use std:: { fs, io:: ErrorKind } ;
13+ #[ cfg( feature = "ui" ) ]
14+ use tauri:: { AppHandle , Emitter } ;
15+ use walkdir:: WalkDir ;
1416
1517pub fn load_paths (
1618 cmd_args : & CmdArgs ,
17- #[ cfg( feature = "ui" ) ]
18- app_handle : & AppHandle
19+ #[ cfg( feature = "ui" ) ] app_handle : & AppHandle ,
1920) -> Vec < String > {
2021 if let Some ( input_file_path) = & cmd_args. file_list {
2122 match fs:: read_to_string ( input_file_path) {
@@ -33,7 +34,8 @@ pub fn load_paths(
3334 exit ( 1 ) ;
3435 }
3536 ErrorKind :: PermissionDenied => {
36- let error = format ! ( "Permission denied when reading file {input_file_path}." ) ;
37+ let error =
38+ format ! ( "Permission denied when reading file {input_file_path}." ) ;
3739 eprintln ! ( "{}" , error) ;
3840 #[ cfg( not( feature = "ui" ) ) ]
3941 exit ( 1 ) ;
@@ -76,6 +78,43 @@ pub fn load_paths(
7678 }
7779 }
7880 } else {
79- cmd_args. input . clone ( ) . unwrap ( )
81+ let paths = cmd_args. input . clone ( ) . unwrap ( ) ;
82+ let mut files: Vec < String > = vec ! [ ] ;
83+
84+ for p in paths {
85+ let path = Path :: new ( & p) ;
86+ if path. is_file ( ) {
87+ files. push ( p) ;
88+ } else if path. is_dir ( ) {
89+ for entry in WalkDir :: new ( path)
90+ . follow_links ( false )
91+ . into_iter ( )
92+ . filter_entry ( |e| !e. path_is_symlink ( ) )
93+ {
94+ match entry {
95+ Ok ( entry) => {
96+ if entry. file_type ( ) . is_file ( ) {
97+ files. push ( entry. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ) ;
98+ }
99+ }
100+ Err ( err) => {
101+ let error = format ! (
102+ "Failed to read directory {}: {}" ,
103+ & err. path( ) . unwrap( ) . display( ) ,
104+ err
105+ ) ;
106+
107+ #[ cfg( not( feature = "ui" ) ) ]
108+ eprintln ! ( "{}" , error) ;
109+
110+ #[ cfg( feature = "ui" ) ]
111+ let _ = app_handle. emit ( "file-list-error" , error) ;
112+ }
113+ }
114+ }
115+ }
116+ }
117+
118+ files
80119 }
81120}
0 commit comments