From c31e194120b36360864511c341e368408cd300c2 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 9 Jan 2024 18:56:36 +0100 Subject: [PATCH] Revert "wildcard: Remove useless access() call for trailing slash" This reverts commit 6823f5e3374f00f43e9d20a4db12d63e0bc5da84. Fixes #10205 --- src/wildcard.cpp | 7 +++++-- tests/checks/wildcard.fish | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 2683cfa1b..2c012637d 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -646,8 +646,11 @@ void wildcard_expander_t::expand_trailing_slash(const wcstring &base_dir, const } if (!(flags & expand_flag::for_completions)) { - // Trailing slash and not accepting incomplete, e.g. `echo /xyz/`. Insert this file, we already know it exists! - this->add_expansion_result(wcstring{base_dir}); + // Trailing slash and not accepting incomplete, e.g. `echo /xyz/`. Insert this file if it + // exists. + if (waccess(base_dir, F_OK) == 0) { + this->add_expansion_result(wcstring{base_dir}); + } } else { // Trailing slashes and accepting incomplete, e.g. `echo /xyz/`. Everything is added. dir_iter_t dir = open_dir(base_dir); diff --git a/tests/checks/wildcard.fish b/tests/checks/wildcard.fish index 189d6dff7..03f28aa81 100644 --- a/tests/checks/wildcard.fish +++ b/tests/checks/wildcard.fish @@ -11,6 +11,10 @@ touch ./b/file.txt set dirs ./a ./b echo $dirs/*.txt # CHECK: ./b/file.txt +echo */foo/ +# CHECKERR: checks/wildcard.fish (line {{\d+}}): No matches for wildcard '*/foo/'. See `help wildcards-globbing`. +# CHECKERR: echo */foo/ +# CHECKERR: ^~~~~^ cd $oldpwd rm -Rf $dir