@@ -35,7 +35,11 @@ mod platform {
3535 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
3636 use nix:: unistd:: { fdatasync, syncfs} ;
3737 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
38- use std:: fs:: File ;
38+ use std:: fs:: { File , OpenOptions } ;
39+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
40+ use std:: os:: unix:: fs:: OpenOptionsExt ;
41+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
42+ use uucore:: display:: Quotable ;
3943 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
4044 use uucore:: error:: FromIo ;
4145 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
@@ -57,7 +61,11 @@ mod platform {
5761 /// Logs a warning if fcntl fails but doesn't abort the operation.
5862 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
5963 fn open_and_reset_nonblock ( path : & str ) -> UResult < File > {
60- let f = File :: open ( path) . map_err_context ( || path. to_string ( ) ) ?;
64+ let f = OpenOptions :: new ( )
65+ . read ( true )
66+ . custom_flags ( OFlag :: O_NONBLOCK . bits ( ) )
67+ . open ( path)
68+ . map_err_context ( || path. to_string ( ) ) ?;
6169 // Reset O_NONBLOCK flag if it was set (matches GNU behavior)
6270 // This is non-critical, so we log errors but don't fail
6371 if let Err ( e) = fcntl ( & f, FcntlArg :: F_SETFL ( OFlag :: empty ( ) ) ) {
@@ -73,7 +81,9 @@ mod platform {
7381 pub fn do_syncfs ( files : Vec < String > ) -> UResult < ( ) > {
7482 for path in files {
7583 let f = open_and_reset_nonblock ( & path) ?;
76- syncfs ( f) ?;
84+ syncfs ( f) . map_err_context (
85+ || translate ! ( "sync-error-syncing-file" , "file" => path. quote( ) ) ,
86+ ) ?;
7787 }
7888 Ok ( ( ) )
7989 }
@@ -82,7 +92,9 @@ mod platform {
8292 pub fn do_fdatasync ( files : Vec < String > ) -> UResult < ( ) > {
8393 for path in files {
8494 let f = open_and_reset_nonblock ( & path) ?;
85- fdatasync ( f) ?;
95+ fdatasync ( f) . map_err_context (
96+ || translate ! ( "sync-error-syncing-file" , "file" => path. quote( ) ) ,
97+ ) ?;
8698 }
8799 Ok ( ( ) )
88100 }
0 commit comments