aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-09-27 17:19:17 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-09-27 17:19:52 -0700
commit11376ae25bfdc90aa60511597163984e43700c22 (patch)
tree5840f672bce8e9eaa7309e6b4cadc4b13f04be7a
parentdd245f62f0f30403961cd71abe8730ea51ab1855 (diff)
Fix for recursive wildcard expansion ignoring directories
When ascending out of a directory, we need to clear the directory from the visited set. Fixes #2414.
-rw-r--r--src/fish_tests.cpp9
-rw-r--r--src/wildcard.cpp5
2 files changed, 13 insertions, 1 deletions
diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp
index 8adf4ca3..78bf0910 100644
--- a/src/fish_tests.cpp
+++ b/src/fish_tests.cpp
@@ -1474,6 +1474,9 @@ static void test_expand()
yyy
bax
xxx
+ lol
+ nub
+ q
.foo
*/
@@ -1481,12 +1484,14 @@ static void test_expand()
if (system("mkdir -p /tmp/fish_expand_test/b/")) err(L"mkdir failed");
if (system("mkdir -p /tmp/fish_expand_test/baz/")) err(L"mkdir failed");
if (system("mkdir -p /tmp/fish_expand_test/bax/")) err(L"mkdir failed");
+ if (system("mkdir -p /tmp/fish_expand_test/lol/nub/")) err(L"mkdir failed");
if (system("touch /tmp/fish_expand_test/.foo")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/b/x")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/bar")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/bax/xxx")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/baz/xxx")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/baz/yyy")) err(L"touch failed");
+ if (system("touch /tmp/fish_expand_test/lol/nub/q")) err(L"touch failed");
// This is checking that .* does NOT match . and .. (https://github.com/fish-shell/fish-shell/issues/270). But it does have to match literal components (e.g. "./*" has to match the same as "*"
const wchar_t * const wnull = NULL;
@@ -1522,6 +1527,10 @@ static void test_expand()
expand_test(L"/tmp/fish_expand_test/b**/", 0,
L"/tmp/fish_expand_test/b/", L"/tmp/fish_expand_test/baz/", L"/tmp/fish_expand_test/bax/", wnull,
L"Glob did the wrong thing 6");
+
+ expand_test(L"/tmp/fish_expand_test/**/q", 0,
+ L"/tmp/fish_expand_test/lol/nub/q", wnull,
+ L"Glob did the wrong thing 7");
expand_test(L"/tmp/fish_expand_test/BA", EXPAND_FOR_COMPLETIONS,
L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax/", L"/tmp/fish_expand_test/baz/", wnull,
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index ad8c8be6..78b38a2d 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -841,6 +841,9 @@ void wildcard_expander_t::expand_intermediate_segment(const wcstring &base_dir,
/* We made it through. Perform normal wildcard expansion on this new directory, starting at our tail_wc, which includes the ANY_STRING_RECURSIVE guy. */
full_path.push_back(L'/');
this->expand(full_path, wc_remainder);
+
+ /* Now remove the visited file. This is for #2414: only directories "beneath" us should be considered visited. */
+ this->visited_files.erase(file_id);
}
}
@@ -1024,7 +1027,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc)
}
else
{
- /* Not the last segment, nonempty wildcard */
+ /* Not the last segment, nonempty wldcard */
assert(next_slash != NULL);
const wchar_t *wc_remainder = next_slash;
while (*wc_remainder == L'/')