@@ -90,3 +90,85 @@ fn test_sync_no_permission_file() {
9090 ts. ccmd ( "chmod" ) . arg ( "0200" ) . arg ( f) . succeeds ( ) ;
9191 ts. ucmd ( ) . arg ( f) . succeeds ( ) ;
9292}
93+
94+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
95+ #[ test]
96+ fn test_sync_data_nonblock_flag_reset ( ) {
97+ // Test that O_NONBLOCK flag is properly reset when syncing files
98+ // This verifies the fix in commit 05612a4792ba2a5ad509cf995b91e868fc261229
99+ use std:: fs:: File ;
100+ use std:: io:: Write ;
101+ use uutests:: util:: TestScenario ;
102+ use uutests:: util_name;
103+
104+ let ts = TestScenario :: new ( util_name ! ( ) ) ;
105+ let at = & ts. fixtures ;
106+ let test_file = "test_file.txt" ;
107+
108+ // Create a test file
109+ at. write ( test_file, "test content" ) ;
110+
111+ // Run sync --data with the file - should succeed
112+ ts. ucmd ( ) . arg ( "--data" ) . arg ( test_file) . succeeds ( ) ;
113+ }
114+
115+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
116+ #[ test]
117+ fn test_sync_fs_nonblock_flag_reset ( ) {
118+ // Test that O_NONBLOCK flag is properly reset when syncing filesystems
119+ use std:: fs;
120+ use tempfile:: tempdir;
121+
122+ let temporary_directory = tempdir ( ) . unwrap ( ) ;
123+ let temporary_path = fs:: canonicalize ( temporary_directory. path ( ) ) . unwrap ( ) ;
124+
125+ // Run sync --file-system with the path - should succeed
126+ new_ucmd ! ( )
127+ . arg ( "--file-system" )
128+ . arg ( & temporary_path)
129+ . succeeds ( ) ;
130+ }
131+
132+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
133+ #[ test]
134+ fn test_sync_fdatasync_error_handling ( ) {
135+ // Test that fdatasync properly handles file opening errors
136+ // This verifies the error handling fix in commit 05612a4792ba2a5ad509cf995b91e868fc261229
137+ new_ucmd ! ( )
138+ . arg ( "--data" )
139+ . arg ( "/nonexistent/path/to/file" )
140+ . fails ( )
141+ . stderr_contains ( "error opening" ) ;
142+ }
143+
144+ #[ cfg( target_os = "macos" ) ]
145+ #[ test]
146+ fn test_sync_syncfs_error_handling_macos ( ) {
147+ // Test that syncfs properly handles invalid paths on macOS
148+ // This verifies the error handling fix in commit 05612a4792ba2a5ad509cf995b91e868fc261229
149+ new_ucmd ! ( )
150+ . arg ( "--file-system" )
151+ . arg ( "/nonexistent/path/to/file" )
152+ . fails ( )
153+ . stderr_contains ( "error opening" ) ;
154+ }
155+
156+ #[ test]
157+ fn test_sync_multiple_files ( ) {
158+ // Test syncing multiple files at once
159+ use std:: fs;
160+ use tempfile:: tempdir;
161+
162+ let temporary_directory = tempdir ( ) . unwrap ( ) ;
163+ let temp_path = temporary_directory. path ( ) ;
164+
165+ // Create multiple test files
166+ let file1 = temp_path. join ( "file1.txt" ) ;
167+ let file2 = temp_path. join ( "file2.txt" ) ;
168+
169+ fs:: write ( & file1, "content1" ) . unwrap ( ) ;
170+ fs:: write ( & file2, "content2" ) . unwrap ( ) ;
171+
172+ // Sync both files
173+ new_ucmd ! ( ) . arg ( "--data" ) . arg ( & file1) . arg ( & file2) . succeeds ( ) ;
174+ }
0 commit comments