@@ -12,7 +12,7 @@ use std::{borrow::Cow, io::Write};
1212
1313use chrono:: { format:: StrftimeItems , DateTime , Local } ;
1414
15- use super :: { FileType , Matcher , MatcherIO , WalkEntry , WalkError } ;
15+ use super :: { FileType , Follow , Matcher , MatcherIO , WalkEntry } ;
1616
1717#[ cfg( unix) ]
1818use std:: os:: unix:: prelude:: MetadataExt ;
@@ -359,18 +359,6 @@ fn get_starting_point(file_info: &WalkEntry) -> &Path {
359359 . unwrap ( )
360360}
361361
362- fn format_non_link_file_type ( file_type : FileType ) -> char {
363- match file_type {
364- FileType :: Regular => 'f' ,
365- FileType :: Directory => 'd' ,
366- FileType :: BlockDevice => 'b' ,
367- FileType :: CharDevice => 'c' ,
368- FileType :: Fifo => 'p' ,
369- FileType :: Socket => 's' ,
370- _ => 'U' ,
371- }
372- }
373-
374362fn format_directive < ' entry > (
375363 file_info : & ' entry WalkEntry ,
376364 directive : & FormatDirective ,
@@ -525,7 +513,7 @@ fn format_directive<'entry>(
525513 FormatDirective :: StartingPoint => get_starting_point ( file_info) . to_string_lossy ( ) ,
526514
527515 FormatDirective :: SymlinkTarget => {
528- if file_info. path_is_symlink ( ) {
516+ if file_info. file_type ( ) . is_symlink ( ) {
529517 fs:: read_link ( file_info. path ( ) ) ?
530518 . to_string_lossy ( )
531519 . into_owned ( )
@@ -535,22 +523,43 @@ fn format_directive<'entry>(
535523 }
536524 }
537525
538- FormatDirective :: Type { follow_links } => if file_info. path_is_symlink ( ) {
539- if * follow_links {
540- match file_info. path ( ) . metadata ( ) . map_err ( WalkError :: from) {
541- Ok ( meta) => format_non_link_file_type ( meta. file_type ( ) . into ( ) ) ,
542- Err ( e) if e. is_not_found ( ) => 'N' ,
543- Err ( e) if e. is_loop ( ) => 'L' ,
544- Err ( _) => '?' ,
545- }
526+ FormatDirective :: Type { follow_links } => {
527+ let follow = if * follow_links {
528+ Follow :: Force
529+ } else if file_info. follow ( ) {
530+ Follow :: Always
546531 } else {
547- 'l'
548- }
549- } else {
550- format_non_link_file_type ( file_info. file_type ( ) )
532+ Follow :: Never
533+ } ;
534+ let meta = follow. metadata ( file_info) ;
535+ let ftype = meta
536+ . as_ref ( )
537+ . map ( |m| m. file_type ( ) . into ( ) )
538+ . unwrap_or ( FileType :: Unknown ) ;
539+
540+ let ret = match ftype {
541+ FileType :: Regular => "f" ,
542+ FileType :: Directory => "d" ,
543+ FileType :: BlockDevice => "b" ,
544+ FileType :: CharDevice => "c" ,
545+ FileType :: Fifo => "p" ,
546+ FileType :: Socket => "s" ,
547+ FileType :: Symlink => "l" ,
548+ FileType :: Unknown if * follow_links => {
549+ match meta {
550+ Err ( e) if e. is_not_found ( ) => "N" ,
551+ Err ( e) if e. is_loop ( ) => "L" ,
552+ Err ( _) => {
553+ // TODO: matcher_io.set_exit_code(1);
554+ "?"
555+ }
556+ _ => "U" ,
557+ }
558+ }
559+ FileType :: Unknown => "U" ,
560+ } ;
561+ ret. into ( )
551562 }
552- . to_string ( )
553- . into ( ) ,
554563
555564 #[ cfg( not( unix) ) ]
556565 FormatDirective :: User { .. } => "0" . into ( ) ,
0 commit comments