diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 5bd21bb1b..4cf5eafb4 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -169,6 +169,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .map(|v| v.map(ToString::to_string).collect()) .unwrap_or_default(); + if matches.is_present(options::DATA) && files.is_empty() { + return Err(USimpleError::new(1, "--data needs at least one argument")); + } + for f in &files { if !Path::new(&f).exists() { return Err(USimpleError::new( diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 97259cdda..e57690e49 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -44,3 +44,11 @@ fn test_sync_no_existing_files() { .fails() .stderr_contains("cannot stat"); } + +#[test] +fn test_sync_data_but_not_file() { + new_ucmd!() + .arg("--data") + .fails() + .stderr_contains("sync: --data needs at least one argument"); +}