Fix panic when opening symlink which points to an inaccessible directory (#6034)

* Fix panic when opening symlink which points to an inaccessible directory

Fixes #6027

Signed-off-by: nibon7 <nibon7@163.com>

* tweak words

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
nibon7 2022-07-13 20:00:30 +08:00 committed by GitHub
parent 61e027b227
commit 47c1f475bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,14 +88,14 @@ impl Command for Open {
if permission_denied(&path) {
#[cfg(unix)]
let error_msg = format!(
"The permissions of {:o} do not allow access for this user",
path.metadata()
.expect("this shouldn't be called since we already know there is a dir")
.permissions()
.mode()
& 0o0777
);
let error_msg = match path.metadata() {
Ok(md) => format!(
"The permissions of {:o} does not allow access for this user",
md.permissions().mode() & 0o0777
),
Err(e) => e.to_string(),
};
#[cfg(not(unix))]
let error_msg = String::from("Permission denied");
Err(ShellError::GenericError(