File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ workspace = true
1818path = " src/sync.rs"
1919
2020[dependencies ]
21+ libc = { workspace = true }
2122clap = { workspace = true }
2223uucore = { workspace = true , features = [" wide" ] }
2324fluent = { workspace = true }
Original file line number Diff line number Diff line change @@ -35,9 +35,9 @@ 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 } ;
3939 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
40- use uucore :: error :: FromIo ;
40+ use std :: os :: unix :: fs :: OpenOptionsExt ;
4141 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
4242 use uucore:: translate;
4343
@@ -57,7 +57,10 @@ mod platform {
5757 /// Logs a warning if fcntl fails but doesn't abort the operation.
5858 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
5959 fn open_and_reset_nonblock ( path : & str ) -> UResult < File > {
60- let f = File :: open ( path) . map_err_context ( || path. to_string ( ) ) ?;
60+ let f = OpenOptions :: new ( )
61+ . read ( true )
62+ . custom_flags ( libc:: O_NONBLOCK )
63+ . open ( path) ?;
6164 // Reset O_NONBLOCK flag if it was set (matches GNU behavior)
6265 // This is non-critical, so we log errors but don't fail
6366 if let Err ( e) = fcntl ( & f, FcntlArg :: F_SETFL ( OFlag :: empty ( ) ) ) {
Original file line number Diff line number Diff line change @@ -167,3 +167,21 @@ fn test_sync_multiple_files() {
167167 // Sync both files
168168 new_ucmd ! ( ) . arg ( "--data" ) . arg ( & file1) . arg ( & file2) . succeeds ( ) ;
169169}
170+
171+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
172+ #[ test]
173+ fn test_sync_data_fifo_fails_immediately ( ) {
174+ use std:: time:: Duration ;
175+ use uutests:: util:: TestScenario ;
176+ use uutests:: util_name;
177+
178+ let ts = TestScenario :: new ( util_name ! ( ) ) ;
179+ let at = & ts. fixtures ;
180+ at. mkfifo ( "testfifo" ) ;
181+
182+ ts. ucmd ( )
183+ . arg ( "--data" )
184+ . arg ( at. plus_as_string ( "testfifo" ) )
185+ . timeout ( Duration :: from_secs ( 2 ) )
186+ . fails ( ) ;
187+ }
You can’t perform that action at this time.
0 commit comments