mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
ls: Fix problems dealing with dangling symlinks
- For dangling symlinks, errors should only be reported if dereferencing options were passed and dereferencing was applicable to the particular symlink - With -i parameter, report '?' as the inode number for dangling symlinks
This commit is contained in:
parent
115eb5eb52
commit
f6cb1324b6
1 changed files with 9 additions and 5 deletions
|
@ -1196,7 +1196,9 @@ fn list(locs: Vec<String>, config: Config) -> i32 {
|
||||||
|
|
||||||
for loc in &locs {
|
for loc in &locs {
|
||||||
let p = PathBuf::from(&loc);
|
let p = PathBuf::from(&loc);
|
||||||
if !p.exists() {
|
let path_data = PathData::new(p, None, None, &config, true);
|
||||||
|
|
||||||
|
if !path_data.md().is_some() {
|
||||||
show_error!("'{}': {}", &loc, "No such file or directory");
|
show_error!("'{}': {}", &loc, "No such file or directory");
|
||||||
/*
|
/*
|
||||||
We found an error, the return code of ls should not be 0
|
We found an error, the return code of ls should not be 0
|
||||||
|
@ -1206,8 +1208,6 @@ fn list(locs: Vec<String>, config: Config) -> i32 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path_data = PathData::new(p, None, None, &config, true);
|
|
||||||
|
|
||||||
let show_dir_contents = match path_data.file_type() {
|
let show_dir_contents = match path_data.file_type() {
|
||||||
Some(ft) => !config.directory && ft.is_dir(),
|
Some(ft) => !config.directory && ft.is_dir(),
|
||||||
None => {
|
None => {
|
||||||
|
@ -1331,7 +1331,7 @@ fn enter_directory(dir: &PathData, config: &Config, out: &mut BufWriter<Stdout>)
|
||||||
|
|
||||||
fn get_metadata(entry: &Path, dereference: bool) -> std::io::Result<Metadata> {
|
fn get_metadata(entry: &Path, dereference: bool) -> std::io::Result<Metadata> {
|
||||||
if dereference {
|
if dereference {
|
||||||
entry.metadata().or_else(|_| entry.symlink_metadata())
|
entry.metadata()
|
||||||
} else {
|
} else {
|
||||||
entry.symlink_metadata()
|
entry.symlink_metadata()
|
||||||
}
|
}
|
||||||
|
@ -1733,7 +1733,11 @@ fn display_file_name(path: &PathData, config: &Config) -> Option<Cell> {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
if config.format != Format::Long && config.inode {
|
if config.format != Format::Long && config.inode {
|
||||||
name = get_inode(path.md()?) + " " + &name;
|
name = path
|
||||||
|
.md()
|
||||||
|
.map_or_else(|| "?".to_string(), |md| get_inode(md))
|
||||||
|
+ " "
|
||||||
|
+ &name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue