Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/uu/basename/src/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use clap::{Arg, ArgAction, Command};
use std::collections::HashMap;
use std::path::{PathBuf, is_separator};
use std::path::PathBuf;
use uucore::display::Quotable;
use uucore::error::{UResult, UUsageError};
use uucore::format_usage;
Expand Down Expand Up @@ -119,17 +119,8 @@ pub fn uu_app() -> Command {
}

fn basename(fullname: &str, suffix: &str) -> String {
// Remove all platform-specific path separators from the end.
let path = fullname.trim_end_matches(is_separator);

// If the path contained *only* suffix characters (for example, if
// `fullname` were "///" and `suffix` were "/"), then `path` would
// be left with the empty string. In that case, we set `path` to be
// the original `fullname` to avoid returning the empty path.
let path = if path.is_empty() { fullname } else { path };

// Convert to path buffer and get last path component
let pb = PathBuf::from(path);
let pb = PathBuf::from(fullname);

pb.components().next_back().map_or_else(String::new, |c| {
let name = c.as_os_str().to_str().unwrap();
Expand Down
Loading