From 37502788f597c8055877147c00cb108026d57028 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Thu, 28 Sep 2023 15:11:48 -0400 Subject: [PATCH] feat: expose mv externals + document for nushell --- src/uu/mv/src/mv.rs | 39 ++++++++++++------------------------- tests/by-util/test_split.rs | 6 +++--- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 63e975bffbf..54210bb97e3 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -23,7 +23,6 @@ use uucore::backup_control::{self, source_is_target_backup, BackupMode}; use uucore::display::Quotable; use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError, UUsageError}; use uucore::fs::{are_hardlinks_or_one_way_symlink_to_same_file, are_hardlinks_to_same_file}; -use uucore::libc::ENOTEMPTY; use uucore::update_control::{self, UpdateMode}; use uucore::{format_usage, help_about, help_section, help_usage, prompt_yes, show}; @@ -440,31 +439,17 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, opts: &Options) -> match rename(sourcepath, &targetpath, opts, multi_progress.as_ref()) { Err(e) if e.to_string().is_empty() => set_exit_code(1), Err(e) => { - match e.raw_os_error() { - Some(ENOTEMPTY) => { - // The error message was changed to match GNU's decision - // when an issue was filed. These will match when merged upstream. - let e = e - .map_err_context(|| format!("cannot overwrite {}", targetpath.quote())); - match multi_progress { - Some(ref pb) => pb.suspend(|| show!(e)), - None => show!(e), - }; - } - _ => { - let e = e.map_err_context(|| { - format!( - "cannot move {} to {}", - sourcepath.quote(), - targetpath.quote() - ) - }); - match multi_progress { - Some(ref pb) => pb.suspend(|| show!(e)), - None => show!(e), - }; - } - } + let e = e.map_err_context(|| { + format!( + "cannot move {} to {}", + sourcepath.quote(), + targetpath.quote() + ) + }); + match multi_progress { + Some(ref pb) => pb.suspend(|| show!(e)), + None => show!(e), + }; } Ok(()) => (), } @@ -535,7 +520,7 @@ fn rename( if is_empty_dir(to) { fs::remove_dir(to)?; } else { - return Err(io::Error::from_raw_os_error(ENOTEMPTY)); + return Err(io::Error::new(io::ErrorKind::Other, "Directory not empty")); } } } diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 7c6d271e6cc..c1cc522d70e 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -448,7 +448,7 @@ fn test_split_obs_lines_within_combined_shorts() { .no_stdout(); let glob = Glob::new(&at, ".", r"x\d\d$"); assert_eq!(glob.count(), 2); - assert_eq!(glob.collate(), at.read_bytes(name)) + assert_eq!(glob.collate(), at.read_bytes(name)); } /// Test for obsolete lines option as part of combined short options with tailing suffix length with value @@ -480,7 +480,7 @@ fn test_split_obs_lines_starts_combined_shorts() { .no_stdout(); let glob = Glob::new(&at, ".", r"x\d\d$"); assert_eq!(glob.count(), 2); - assert_eq!(glob.collate(), at.read_bytes(name)) + assert_eq!(glob.collate(), at.read_bytes(name)); } /// Test for using both obsolete lines (standalone) option and short/long lines option simultaneously @@ -615,7 +615,7 @@ fn test_split_multiple_obs_lines_within_combined() { .no_stdout(); let glob = Glob::new(&at, ".", r"x\d\d$"); assert_eq!(glob.count(), 2); - assert_eq!(glob.collate(), at.read_bytes(name)) + assert_eq!(glob.collate(), at.read_bytes(name)); } /// Test for using both obsolete lines option within combined shorts with conflicting -n option simultaneously