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:
Jason Gedge 2019-10-13 12:00:30 -04:00
parent 2716bb020f
commit 341cc1ea63

View File

@ -128,15 +128,18 @@ impl Shell for FilesystemShell {
}
if let Ok(entry) = entry {
let filepath = entry.path();
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, &entry.metadata().unwrap(), &name_tag)?;
let value = dir_entry_dict(filename, &metadata, &name_tag)?;
yield ReturnSuccess::value(value);
}
}
}
};
return Ok(stream.to_output_stream());
}
@ -164,17 +167,19 @@ impl Shell for FilesystemShell {
break;
}
if let Ok(entry) = entry {
if let Ok(metadata) = std::fs::symlink_metadata(&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);
}
}
}
}
};
Ok(stream.to_output_stream())
}