diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index b91f216aaed..e426ee68df9 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -260,8 +260,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { #[allow(clippy::if_same_then_else)] if matches.get_flag(options::FILE_SYSTEM) { - #[cfg(any(target_os = "linux", target_os = "android", target_os = "windows"))] - syncfs(files)?; + if files.is_empty() { + sync()?; + } else { + #[cfg(any(target_os = "linux", target_os = "android", target_os = "windows"))] + syncfs(files)?; + } } else if matches.get_flag(options::DATA) { #[cfg(any(target_os = "linux", target_os = "android"))] fdatasync(files)?; diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 8c09d86372a..fdb93b72fd4 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -31,6 +31,11 @@ fn test_sync_fs() { .succeeds(); } +#[test] +fn test_sync_fs_without_files_falls_back_to_full_sync() { + new_ucmd!().arg("--file-system").succeeds(); +} + #[test] fn test_sync_data() { // Todo add a second arg