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