mirror of
https://github.com/uutils/coreutils
synced 2024-10-15 12:24:09 +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
|
@ -1196,7 +1196,9 @@ fn list(locs: Vec<String>, config: Config) -> i32 {
|
|||
|
||||
for loc in &locs {
|
||||
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");
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
let path_data = PathData::new(p, None, None, &config, true);
|
||||
|
||||
let show_dir_contents = match path_data.file_type() {
|
||||
Some(ft) => !config.directory && ft.is_dir(),
|
||||
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> {
|
||||
if dereference {
|
||||
entry.metadata().or_else(|_| entry.symlink_metadata())
|
||||
entry.metadata()
|
||||
} else {
|
||||
entry.symlink_metadata()
|
||||
}
|
||||
|
@ -1733,7 +1733,11 @@ fn display_file_name(path: &PathData, config: &Config) -> Option<Cell> {
|
|||
#[cfg(unix)]
|
||||
{
|
||||
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…
Reference in a new issue