mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Move path_ends_with_terminator from mv into uucore
This commit is contained in:
parent
4c698d58e0
commit
108dc4a0cd
2 changed files with 23 additions and 20 deletions
|
@ -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();
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue