@@ -599,65 +599,78 @@ fn analyze_file(mut path: String, args: &Args) {
599599 magic_files. push ( get_default_magic_file ( ) ) ;
600600 }
601601
602- match fs:: symlink_metadata ( & path) {
603- Ok ( met) => {
604- let file_type = met. file_type ( ) ;
602+ let met = match fs:: symlink_metadata ( & path) {
603+ Ok ( met) => met,
604+ Err ( _) => {
605+ println ! ( "{path}: cannot open" ) ;
606+ return ;
607+ }
608+ } ;
605609
606- if file_type. is_symlink ( ) {
607- if args. identify_as_symbolic_link {
608- println ! ( "{path}: symbolic link" ) ;
610+ let file_type = met. file_type ( ) ;
611+
612+ if file_type. is_symlink ( ) {
613+ if args. identify_as_symbolic_link {
614+ println ! ( "{path}: symbolic link" ) ;
615+ return ;
616+ }
617+ match read_link ( & path) {
618+ Ok ( file_p) => {
619+ // trace the file pointed by symbolic link
620+ if file_p. exists ( ) {
621+ println ! ( "{path}: symbolic link to {}" , file_p. to_str( ) . unwrap( ) ) ;
609622 } else {
610- match read_link ( & path) {
611- Ok ( file_p) => {
612- // trace the file pointed by symbolic link
613- if file_p. exists ( ) {
614- println ! ( "{path}: symbolic link to {}" , file_p. to_str( ) . unwrap( ) ) ;
615- } else {
616- println ! (
617- "{path}: broken symbolic link to {}" ,
618- file_p. to_str( ) . unwrap( )
619- ) ;
620- }
621- }
622- Err ( _) => {
623- println ! ( "{path}: symbolic link" ) ;
624- }
625- }
623+ println ! (
624+ "{path}: broken symbolic link to {}" ,
625+ file_p. to_str( ) . unwrap( )
626+ ) ;
626627 }
627- } else if file_type. is_char_device ( ) {
628- println ! ( "{path}: character special" ) ;
629- } else if file_type. is_dir ( ) {
630- println ! ( "{path}: directory" ) ;
631- } else if file_type. is_fifo ( ) {
632- println ! ( "{path}: fifo" ) ;
633- } else if file_type. is_socket ( ) {
634- println ! ( "{path}: socket" ) ;
635628 }
636- if file_type. is_block_device ( ) {
637- println ! ( "{path}: block special" ) ;
638- } else if file_type. is_file ( ) {
639- if args. no_further_file_classification {
640- println ! ( "{path}: regular file" ) ;
641- } else {
642- if met. len ( ) == 0 {
643- println ! ( "{path}: empty" ) ;
644- } else {
645- match get_type_from_magic_file_dbs ( & PathBuf :: from ( & path) , & magic_files) {
646- Some ( f_type) => {
647- println ! ( "{path}: {f_type}" ) ;
648- }
649- None => {
650- println ! ( "{path}: data" ) ;
651- }
652- }
653- }
654- }
629+ Err ( _) => {
630+ println ! ( "{path}: symbolic link" ) ;
655631 }
656632 }
657- Err ( _) => {
658- println ! ( "{path}: cannot open" ) ;
633+ return ;
634+ }
635+ if file_type. is_char_device ( ) {
636+ println ! ( "{path}: character special" ) ;
637+ return ;
638+ }
639+ if file_type. is_dir ( ) {
640+ println ! ( "{path}: directory" ) ;
641+ return ;
642+ }
643+ if file_type. is_fifo ( ) {
644+ println ! ( "{path}: fifo" ) ;
645+ return ;
646+ }
647+ if file_type. is_socket ( ) {
648+ println ! ( "{path}: socket" ) ;
649+ return ;
650+ }
651+ if file_type. is_block_device ( ) {
652+ println ! ( "{path}: block special" ) ;
653+ return ;
654+ }
655+ if file_type. is_file ( ) {
656+ if args. no_further_file_classification {
657+ println ! ( "{path}: regular file" ) ;
658+ return ;
659+ }
660+ if met. len ( ) == 0 {
661+ println ! ( "{path}: empty" ) ;
662+ return ;
663+ }
664+ match get_type_from_magic_file_dbs ( & PathBuf :: from ( & path) , & magic_files) {
665+ Some ( f_type) => {
666+ println ! ( "{path}: {f_type}" ) ;
667+ }
668+ None => {
669+ println ! ( "{path}: data" ) ;
670+ }
659671 }
660672 }
673+ unreachable ! ( ) ;
661674}
662675
663676fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
0 commit comments