@@ -27,7 +27,6 @@ use chunks::ReverseChunks;
2727use follow:: Observer ;
2828use memchr:: { memchr_iter, memrchr_iter} ;
2929use paths:: { FileExtTail , HeaderPrinter , Input , InputKind } ;
30- use same_file:: Handle ;
3130use std:: cmp:: Ordering ;
3231use std:: fs:: File ;
3332use std:: io:: { self , BufReader , BufWriter , ErrorKind , Read , Seek , SeekFrom , Write , stdin, stdout} ;
@@ -117,21 +116,21 @@ fn tail_file(
117116 observer : & mut Observer ,
118117 offset : u64 ,
119118) -> UResult < ( ) > {
120- let md = path. metadata ( ) ;
121- if let Err ( ref e ) = md {
122- if e. kind ( ) == ErrorKind :: NotFound {
123- set_exit_code ( 1 ) ;
124- show_error ! (
125- "{}" ,
126- translate! (
127- "tail-error-cannot-open-no-such-file" ,
128- " file" => input . display_name . clone ( ) ,
129- "error " => translate! ( "tail-no-such-file-or-directory" )
130- )
131- ) ;
132- observer . add_bad_path ( path , input . display_name . as_str ( ) , false ) ? ;
133- return Ok ( ( ) ) ;
134- }
119+ if path
120+ . metadata ( )
121+ . is_err_and ( |e| e. kind ( ) == ErrorKind :: NotFound )
122+ {
123+ set_exit_code ( 1 ) ;
124+ show_error ! (
125+ "{}" ,
126+ translate! (
127+ "tail-error-cannot-open-no-such- file",
128+ "file " => input . display_name . clone ( ) ,
129+ "error" => translate! ( "tail-no-such-file-or-directory" )
130+ )
131+ ) ;
132+ observer . add_bad_path ( path , input . display_name . as_str ( ) , false ) ? ;
133+ return Ok ( ( ) ) ;
135134 }
136135
137136 if path. is_dir ( ) {
@@ -261,7 +260,7 @@ fn tail_stdin(
261260 // on macOS and Linux.
262261 #[ cfg( target_os = "macos" ) ]
263262 {
264- if let Ok ( mut stdin_handle) = Handle :: stdin ( ) {
263+ if let Ok ( mut stdin_handle) = same_file :: Handle :: stdin ( ) {
265264 if let Ok ( meta) = stdin_handle. as_file_mut ( ) . metadata ( ) {
266265 if meta. file_type ( ) . is_dir ( ) {
267266 set_exit_code ( 1 ) ;
@@ -287,17 +286,14 @@ fn tail_stdin(
287286 }
288287
289288 if let Some ( path) = input. resolve ( ) {
290- // fifo
291- let mut stdin_offset = 0 ;
292- if cfg ! ( unix) {
293- // Save the current seek position/offset of a stdin redirected file.
294- // This is needed to pass "gnu/tests/tail-2/start-middle.sh"
295- if let Ok ( mut stdin_handle) = Handle :: stdin ( ) {
296- if let Ok ( offset) = stdin_handle. as_file_mut ( ) . stream_position ( ) {
297- stdin_offset = offset;
298- }
299- }
300- }
289+ #[ cfg( not( unix) ) ]
290+ let stdin_offset = 0 ;
291+ // Save the current seek position/offset of a stdin redirected file.
292+ // This is needed to pass "gnu/tests/tail-2/start-middle.sh"
293+ #[ cfg( unix) ]
294+ let stdin_offset = same_file:: Handle :: stdin ( )
295+ . and_then ( |mut h| h. as_file_mut ( ) . stream_position ( ) )
296+ . unwrap_or ( 0 ) ; // fifo
301297 tail_file (
302298 settings,
303299 header_printer,
@@ -433,10 +429,8 @@ fn backwards_thru_file(file: &mut File, num_delimiters: u64, delimiter: u8) {
433429
434430 // Ignore a trailing newline in the last block, if there is one.
435431 if first_slice {
436- if let Some ( c) = slice. last ( ) {
437- if * c == delimiter {
438- iter. next ( ) ;
439- }
432+ if slice. last ( ) . is_some_and ( |& c| c == delimiter) {
433+ iter. next ( ) ;
440434 }
441435 first_slice = false ;
442436 }
0 commit comments