mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
Merge pull request #2245 from siebenHeaven/fix_ls_path_printing
Fix ls path printing
This commit is contained in:
commit
c83eaf195a
2 changed files with 31 additions and 17 deletions
|
@ -1110,7 +1110,7 @@ struct PathData {
|
|||
md: OnceCell<Option<Metadata>>,
|
||||
ft: OnceCell<Option<FileType>>,
|
||||
// Name of the file - will be empty for . or ..
|
||||
file_name: String,
|
||||
display_name: String,
|
||||
// PathBuf that all above data corresponds to
|
||||
p_buf: PathBuf,
|
||||
must_dereference: bool,
|
||||
|
@ -1126,14 +1126,18 @@ impl PathData {
|
|||
) -> Self {
|
||||
// We cannot use `Path::ends_with` or `Path::Components`, because they remove occurrences of '.'
|
||||
// For '..', the filename is None
|
||||
let name = if let Some(name) = file_name {
|
||||
let display_name = if let Some(name) = file_name {
|
||||
name
|
||||
} else {
|
||||
let display_osstr = if command_line {
|
||||
p_buf.as_os_str()
|
||||
} else {
|
||||
p_buf
|
||||
.file_name()
|
||||
.unwrap_or_else(|| p_buf.iter().next_back().unwrap())
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
};
|
||||
|
||||
display_osstr.to_string_lossy().into_owned()
|
||||
};
|
||||
let must_dereference = match &config.dereference {
|
||||
Dereference::All => true,
|
||||
|
@ -1159,7 +1163,7 @@ impl PathData {
|
|||
Self {
|
||||
md: OnceCell::new(),
|
||||
ft,
|
||||
file_name: name,
|
||||
display_name,
|
||||
p_buf,
|
||||
must_dereference,
|
||||
}
|
||||
|
@ -1243,7 +1247,7 @@ fn sort_entries(entries: &mut Vec<PathData>, config: &Config) {
|
|||
entries.sort_by_key(|k| Reverse(k.md().as_ref().map(|md| md.len()).unwrap_or(0)))
|
||||
}
|
||||
// The default sort in GNU ls is case insensitive
|
||||
Sort::Name => entries.sort_by(|a, b| a.file_name.cmp(&b.file_name)),
|
||||
Sort::Name => entries.sort_by(|a, b| a.display_name.cmp(&b.display_name)),
|
||||
Sort::Version => entries.sort_by(|a, b| version_cmp::version_cmp(&a.p_buf, &b.p_buf)),
|
||||
Sort::Extension => entries.sort_by(|a, b| {
|
||||
a.p_buf
|
||||
|
@ -1719,7 +1723,7 @@ fn classify_file(path: &PathData) -> Option<char> {
|
|||
}
|
||||
|
||||
fn display_file_name(path: &PathData, config: &Config) -> Option<Cell> {
|
||||
let mut name = escape_name(&path.file_name, &config.quoting_style);
|
||||
let mut name = escape_name(&path.display_name, &config.quoting_style);
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
|
|
|
@ -1967,8 +1967,6 @@ fn test_ls_sort_extension() {
|
|||
);
|
||||
}
|
||||
|
||||
// This tests for the open issue described in #2223
|
||||
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
|
||||
#[test]
|
||||
fn test_ls_path() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
@ -1987,13 +1985,25 @@ fn test_ls_path() {
|
|||
scene.ucmd().arg(path).run().stdout_is(expected_stdout);
|
||||
|
||||
let expected_stdout = &format!("./{}\n", path);
|
||||
scene.ucmd().arg(path).run().stdout_is(expected_stdout);
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(format!("./{}", path))
|
||||
.run()
|
||||
.stdout_is(expected_stdout);
|
||||
|
||||
let abs_path = format!("{}/{}\n", at.as_string(), path);
|
||||
println!(":{}", abs_path);
|
||||
scene.ucmd().arg(&abs_path).run().stdout_is(&abs_path);
|
||||
let abs_path = format!("{}/{}", at.as_string(), path);
|
||||
let expected_stdout = if cfg!(windows) {
|
||||
format!("\'{}\'\n", abs_path)
|
||||
} else {
|
||||
format!("{}\n", abs_path)
|
||||
};
|
||||
scene.ucmd().arg(&abs_path).run().stdout_is(expected_stdout);
|
||||
|
||||
let expected_stdout = &format!("{}\n{}\n", file1, path);
|
||||
let expected_stdout = if cfg!(windows) {
|
||||
format!("{} {}\n", path, file1)
|
||||
} else {
|
||||
format!("{}\n{}\n", path, file1)
|
||||
};
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(file1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue