1414
1515mod  diff_util; 
1616
17- use  std:: { fs,  io,  path:: PathBuf } ; 
18- 
1917use  clap:: Parser ; 
2018use  diff_util:: { 
2119    common:: { FormatOptions ,  OutputFormat } , 
2220    diff_exit_status:: DiffExitStatus , 
2321    dir_diff:: DirDiff , 
2422    file_diff:: FileDiff , 
25-     functions:: check_existance , 
23+     functions:: check_existence , 
2624} ; 
2725use  gettextrs:: { bind_textdomain_codeset,  setlocale,  textdomain,  LocaleCategory } ; 
26+ use  std:: { fs,  io,  path:: PathBuf } ; 
2827
2928/// diff - compare two files 
3029#[ derive( Parser ,  Clone ) ]  
@@ -54,6 +53,10 @@ struct Args {
5453     #[ arg( short,  long) ]  
5554    recurse :  bool , 
5655
56+     /// Print a message even when there are no differences between files 
57+      #[ arg( short = 's' ,  long = "report-identical-files" ) ]  
58+     report_identical_files :  bool , 
59+ 
5760    /// Output 3 lines of unified context 
5861     #[ arg( short) ]  
5962    unified3 :  bool , 
@@ -103,17 +106,16 @@ impl From<&Args> for OutputFormat {
103106} 
104107
105108fn  check_difference ( args :  Args )  -> io:: Result < DiffExitStatus >  { 
106-     let  path1 = PathBuf :: from ( & args. file1 ) ; 
107-     let  path2 = PathBuf :: from ( & args. file2 ) ; 
109+     let  path1 = PathBuf :: from ( args. file1 . as_str ( ) ) ; 
110+     let  path2 = PathBuf :: from ( args. file2 . as_str ( ) ) ; 
108111
109-     let  path1_exists  = check_existance ( & path1) ? ; 
110-     let  path2_exists  = check_existance ( & path2) ? ; 
112+     let  path1_path  = path1. as_path ( ) ; 
113+     let  path2_path  = path2. as_path ( ) ; 
111114
112-     if  !path1_exists || !path2_exists { 
113-         return  Ok ( DiffExitStatus :: Trouble ) ; 
114-     } 
115+     let  path1_exists = check_existence ( path1_path) ; 
116+     let  path2_exists = check_existence ( path2_path) ; 
115117
116-     if  path1 == path2  { 
118+     if  !path1_exists || !path2_exists  { 
117119        return  Ok ( DiffExitStatus :: Trouble ) ; 
118120    } 
119121
@@ -124,18 +126,24 @@ fn check_difference(args: Args) -> io::Result<DiffExitStatus> {
124126        output_format, 
125127        args. label , 
126128        args. label2 , 
129+         args. report_identical_files , 
127130    ) ; 
131+ 
128132    let  format_options = format_options. unwrap ( ) ; 
129133
130-     let  path1_is_file = fs:: metadata ( & path1 ) ?. is_file ( ) ; 
131-     let  path2_is_file = fs:: metadata ( & path2 ) ?. is_file ( ) ; 
134+     let  path1_is_file = fs:: metadata ( path1_path ) ?. is_file ( ) ; 
135+     let  path2_is_file = fs:: metadata ( path2_path ) ?. is_file ( ) ; 
132136
133137    if  path1_is_file && path2_is_file { 
134-         FileDiff :: file_diff ( path1 ,  path2 ,  & format_options,  None ) 
138+         FileDiff :: file_diff ( path1_path ,  path2_path ,  & format_options,  None ) 
135139    }  else  if  !path1_is_file && !path2_is_file { 
136-         DirDiff :: dir_diff ( path1 ,  path2 ,  & format_options,  args. recurse ) 
140+         DirDiff :: dir_diff ( path1_path ,  path2_path ,  & format_options,  args. recurse ) 
137141    }  else  { 
138-         FileDiff :: file_dir_diff ( path1,  path2,  & format_options) 
142+         Ok ( FileDiff :: file_dir_diff ( 
143+             path1_path, 
144+             path2_path, 
145+             & format_options, 
146+         ) ?) 
139147    } 
140148} 
141149
@@ -151,7 +159,7 @@ fn main() -> DiffExitStatus {
151159    match  result { 
152160        Ok ( diff_exit_status)  => diff_exit_status, 
153161        Err ( error)  => { 
154-             eprintln ! ( "diff: {}"  ,  error ) ; 
162+             eprintln ! ( "diff: {error}"  ) ; 
155163
156164            DiffExitStatus :: Trouble 
157165        } 
0 commit comments