diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 19a7c274f..c95e54028 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -23,7 +23,10 @@ use std::path::{Path, PathBuf}; use uucore::backup_control::{self, source_is_target_backup}; use uucore::display::Quotable; use uucore::error::{set_exit_code, FromIo, UResult, USimpleError, UUsageError}; -use uucore::fs::{are_hardlinks_or_one_way_symlink_to_same_file, are_hardlinks_to_same_file}; +use uucore::fs::{ + are_hardlinks_or_one_way_symlink_to_same_file, are_hardlinks_to_same_file, + path_ends_with_terminator, +}; use uucore::update_control; // These are exposed for projects (e.g. nushell) that want to create an `Options` value, which // requires these enums @@ -104,25 +107,6 @@ static OPT_VERBOSE: &str = "verbose"; static OPT_PROGRESS: &str = "progress"; static ARG_FILES: &str = "files"; -/// Returns true if the passed `path` ends with a path terminator. -#[cfg(unix)] -fn path_ends_with_terminator(path: &Path) -> bool { - use std::os::unix::prelude::OsStrExt; - path.as_os_str() - .as_bytes() - .last() - .map_or(false, |&byte| byte == b'/' || byte == b'\\') -} - -#[cfg(windows)] -fn path_ends_with_terminator(path: &Path) -> bool { - use std::os::windows::prelude::OsStrExt; - path.as_os_str() - .encode_wide() - .last() - .map_or(false, |wide| wide == b'/'.into() || wide == b'\\'.into()) -} - #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut app = uu_app(); diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 6eb809e6d..7033646b6 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -714,6 +714,25 @@ pub fn are_hardlinks_or_one_way_symlink_to_same_file(source: &Path, target: &Pat source_metadata.ino() == target_metadata.ino() && source_metadata.dev() == target_metadata.dev() } +/// Returns true if the passed `path` ends with a path terminator. +#[cfg(unix)] +pub fn path_ends_with_terminator(path: &Path) -> bool { + use std::os::unix::prelude::OsStrExt; + path.as_os_str() + .as_bytes() + .last() + .map_or(false, |&byte| byte == b'/' || byte == b'\\') +} + +#[cfg(windows)] +pub fn path_ends_with_terminator(path: &Path) -> bool { + use std::os::windows::prelude::OsStrExt; + path.as_os_str() + .encode_wide() + .last() + .map_or(false, |wide| wide == b'/'.into() || wide == b'\\'.into()) +} + #[cfg(test)] mod tests { // Note this useful idiom: importing names from outer (for mod tests) scope.