1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

ls: Change symlink behavior to be more POSIX compliant.

Symlink directories are read by default, and symlink targets are listed on
Windows.
This commit is contained in:
Zephiris 2016-11-04 21:03:54 -07:00
parent ca8f5516e9
commit 606c1badd2

View file

@ -147,7 +147,7 @@ fn list(options: getopts::Matches) {
if p.is_dir() && !options.opt_present("d") {
dir = true;
if !options.opt_present("L") {
if options.opt_present("l") && !(options.opt_present("L")) {
if let Ok(md) = p.symlink_metadata() {
if md.file_type().is_symlink() {
dir = false;
@ -451,6 +451,21 @@ fn display_file_name(path: &Path,
name.push('@');
}
}
if options.opt_present("long") && metadata.file_type().is_symlink() {
if let Ok(target) = path.read_link() {
// We don't bother updating width here because it's not used for long listings
let code = if target.exists() {
"fi"
} else {
"mi"
};
let target_name = target.to_string_lossy().to_string();
name.push_str(" -> ");
name.push_str(&target_name);
}
}
name.into()
}