@@ -547,27 +547,18 @@ fn get_type_from_magic_file_dbs(test_file: &PathBuf, magic_file_dbs: &[PathBuf])
547547 } )
548548}
549549
550- /// Get the default raw(text based) magic file
551- fn get_default_magic_file ( ) -> PathBuf {
552- #[ cfg( target_os = "macos" ) ]
553- {
554- PathBuf :: from ( "/usr/share/file/magic/magic" )
555- }
556- #[ cfg( not( target_os = "macos" ) ) ]
557- {
558- PathBuf :: from ( "/etc/magic" )
559- }
560- }
561-
562- fn analyze_file ( mut path : String , args : & Args ) {
550+ #[ cfg( target_os = "macos" ) ]
551+ /// Default raw (text based) magic file
552+ const DEFAULT_MAGIC_FILE : & str = "/usr/share/file/magic/magic" ;
553+ #[ cfg( not( target_os = "macos" ) ) ]
554+ /// Default raw (text based) magic file
555+ const DEFAULT_MAGIC_FILE : & str = "/etc/magic" ;
556+
557+ fn get_magic_files ( args : & Args ) -> Vec < PathBuf > {
563558 // set priority according to the occurence of flags in the args lowest index will get highest priority
564559 let mut magic_files: Vec < PathBuf > = Vec :: new ( ) ;
565560
566- if path == "-" {
567- path = String :: new ( ) ;
568- io:: stdin ( ) . read_line ( & mut path) . unwrap ( ) ;
569- path = path. trim ( ) . to_string ( ) ;
570- }
561+ let default_magic_file = PathBuf :: from ( DEFAULT_MAGIC_FILE ) ;
571562
572563 if let Some ( test_file2) = & args. test_file2 {
573564 magic_files. push ( test_file2. clone ( ) ) ;
@@ -579,24 +570,34 @@ fn analyze_file(mut path: String, args: &Args) {
579570
580571 if m_index > h_index {
581572 magic_files. push ( args. test_file1 . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
582- magic_files. push ( get_default_magic_file ( ) ) ;
573+ magic_files. push ( default_magic_file ) ;
583574 } else {
584- magic_files. push ( get_default_magic_file ( ) ) ;
575+ magic_files. push ( default_magic_file ) ;
585576 magic_files. push ( args. test_file1 . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
586577 }
587578 } else if args. test_file1 . is_some ( ) {
588579 magic_files. push ( args. test_file1 . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
589580 } else if args. default_tests {
590- magic_files. push ( get_default_magic_file ( ) ) ;
581+ magic_files. push ( default_magic_file ) ;
591582 }
592583 } else if let Some ( test_file1) = & args. test_file1 {
593584 magic_files. push ( test_file1. clone ( ) ) ;
594585
595586 if args. test_file2 . is_none ( ) && !args. default_tests {
596- magic_files. push ( get_default_magic_file ( ) ) ;
587+ magic_files. push ( default_magic_file ) ;
597588 }
598589 } else {
599- magic_files. push ( get_default_magic_file ( ) ) ;
590+ magic_files. push ( default_magic_file) ;
591+ }
592+
593+ magic_files
594+ }
595+
596+ fn analyze_file ( mut path : String , args : & Args , magic_files : & Vec < PathBuf > ) {
597+ if path == "-" {
598+ path = String :: new ( ) ;
599+ io:: stdin ( ) . read_line ( & mut path) . unwrap ( ) ;
600+ path = path. trim ( ) . to_string ( ) ;
600601 }
601602
602603 let met = match fs:: symlink_metadata ( & path) {
@@ -682,8 +683,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
682683 textdomain ( PROJECT_NAME ) . unwrap ( ) ;
683684 bind_textdomain_codeset ( PROJECT_NAME , "UTF-8" ) . unwrap ( ) ;
684685
686+ let magic_files = get_magic_files ( & args) ;
687+
685688 for file in & args. files {
686- analyze_file ( file. clone ( ) , & args) ;
689+ analyze_file ( file. clone ( ) , & args, & magic_files ) ;
687690 }
688691
689692 Ok ( ( ) )
0 commit comments