diff --git a/crates/nu-command/src/path/exists.rs b/crates/nu-command/src/path/exists.rs index f00e6c17ef..3e40bef28a 100644 --- a/crates/nu-command/src/path/exists.rs +++ b/crates/nu-command/src/path/exists.rs @@ -39,7 +39,8 @@ impl Command for SubCommand { fn extra_description(&self) -> &str { r#"This only checks if it is possible to either `open` or `cd` to the given path. -If you need to distinguish dirs and files, please use `path type`."# +If you need to distinguish dirs and files, please use `path type`. +Also note that if you don't have a permission to a directory of a path, false will be returned"# } fn is_const(&self) -> bool { @@ -147,7 +148,7 @@ fn exists(path: &Path, span: Span, args: &Arguments) -> Value { |_| Ok(true), ) } else { - path.try_exists() + Ok(path.exists()) }; Value::bool( match exists { diff --git a/crates/nu-command/tests/commands/path/exists.rs b/crates/nu-command/tests/commands/path/exists.rs index 96fa02c0e8..faafac910c 100644 --- a/crates/nu-command/tests/commands/path/exists.rs +++ b/crates/nu-command/tests/commands/path/exists.rs @@ -64,6 +64,18 @@ fn const_path_exists() { assert_eq!(actual.out, "true"); } +#[test] +fn path_exists_under_a_non_directory() { + Playground::setup("path_exists_6", |dirs, _| { + let actual = nu!( + cwd: dirs.test(), + "touch test_file; 'test_file/aaa' | path exists" + ); + assert_eq!(actual.out, "false"); + assert!(actual.err.is_empty()); + }) +} + #[test] fn test_check_symlink_exists() { use nu_test_support::{nu, playground::Playground};