mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01:00
Ignore errors in ls
.
`std::fs::metadata` will attempt to follow symlinks, which results in a "No such file or directory" error if the path pointed to by the symlink does not exist. This shouldn't prevent `ls` from succeeding, so we ignore errors. Also, switching to use of `symlink_metadata` means we get stat info on the symlink itself, not what it points to. This means `ls` will now include broken symlinks in its listing.
This commit is contained in:
parent
2716bb020f
commit
341cc1ea63
@ -128,13 +128,16 @@ impl Shell for FilesystemShell {
|
||||
}
|
||||
if let Ok(entry) = entry {
|
||||
let filepath = entry.path();
|
||||
let filename = if let Ok(fname) = filepath.strip_prefix(&cwd) {
|
||||
fname
|
||||
} else {
|
||||
Path::new(&filepath)
|
||||
};
|
||||
let value = dir_entry_dict(filename, &entry.metadata().unwrap(), &name_tag)?;
|
||||
yield ReturnSuccess::value(value);
|
||||
if let Ok(metadata) = std::fs::symlink_metadata(&filepath) {
|
||||
let filename = if let Ok(fname) = filepath.strip_prefix(&cwd) {
|
||||
fname
|
||||
} else {
|
||||
Path::new(&filepath)
|
||||
};
|
||||
|
||||
let value = dir_entry_dict(filename, &metadata, &name_tag)?;
|
||||
yield ReturnSuccess::value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -164,14 +167,16 @@ impl Shell for FilesystemShell {
|
||||
break;
|
||||
}
|
||||
if let Ok(entry) = entry {
|
||||
let filename = if let Ok(fname) = entry.strip_prefix(&cwd) {
|
||||
fname
|
||||
} else {
|
||||
Path::new(&entry)
|
||||
};
|
||||
let metadata = std::fs::metadata(&entry).unwrap();
|
||||
if let Ok(value) = dir_entry_dict(filename, &metadata, &name_tag) {
|
||||
yield ReturnSuccess::value(value);
|
||||
if let Ok(metadata) = std::fs::symlink_metadata(&entry) {
|
||||
let filename = if let Ok(fname) = entry.strip_prefix(&cwd) {
|
||||
fname
|
||||
} else {
|
||||
Path::new(&entry)
|
||||
};
|
||||
|
||||
if let Ok(value) = dir_entry_dict(filename, &metadata, &name_tag) {
|
||||
yield ReturnSuccess::value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user