From: Devin Hussey <husseydevin@gmail.com>
To: zsh-workers@zsh.org
Subject: [PATCH] Ignore EACCES when doing non-pure globbing
Date: Tue, 12 Jan 2021 17:42:56 -0500 [thread overview]
Message-ID: <CAEtFKsvbVi_qeiAhEgKPyp1uasen2TtLj7J0L9gTfQY5NoiGaw@mail.gmail.com> (raw)
Even if we can't access a parent folder, there is still a chance we can
access a subdirectory.
This is notoriously the case on Android, where apps can access their own
subfolders in /data, but not /data itself.
This was causing many issues with Termux, the terminal emulator which
runs from /data on Android, as many scripts will try to glob relative to
the home directory, and it would error when it tried to opendir() on /data.
Over-recursion does not seem to be an issue, as EACCES seems to have
lower priority than ENOENT or ENOTDIR, at least on Linux.
See:
- https://github.com/sorin-ionescu/prezto/issues/1560
- https://github.com/termux/termux-packages/issues/1894
Signed-off-by: Devin Hussey <husseydevin@gmail.com>
---
Src/glob.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/Src/glob.c b/Src/glob.c
index bee890caf..7b9414c6f 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -585,9 +585,11 @@ scanner(Complist q, int shortcircuit)
char *subdirs = NULL;
int subdirlen = 0;
- if (lock == NULL)
+ /* Ignore EACCES. We may be in a jail like Android's /data where we can
+ * only access specific subfolders. */
+ if (lock == NULL && errno != EACCES)
return;
- while ((fn = zreaddir(lock, 1)) && !errflag) {
+ while (lock != NULL && (fn = zreaddir(lock, 1)) && !errflag) {
/* prefix and suffix are zle trickery */
if (!dirs && !colonmod &&
((glob_pre && !strpfx(glob_pre, fn))
@@ -673,7 +675,8 @@ scanner(Complist q, int shortcircuit)
}
}
}
- closedir(lock);
+ if (lock != NULL)
+ closedir(lock);
if (subdirs) {
int oppos = pathpos;
--
2.30.0
next reply other threads:[~2021-01-12 22:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 22:42 Devin Hussey [this message]
2021-01-12 22:48 ` Devin Hussey
2021-01-12 23:47 ` Lawrence Velázquez
2021-01-13 0:53 ` Devin Hussey
2021-01-13 1:12 ` Devin Hussey
2021-01-13 1:28 ` Bart Schaefer
2021-01-13 1:26 ` Mikael Magnusson
[not found] ` <CAEtFKsuDqhu3USSVCcrt-8rkvA_yAkHt=eU+FY6=pNu+gVogMw@mail.gmail.com>
2021-01-13 2:14 ` Devin Hussey
2021-01-13 3:01 ` Devin Hussey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAEtFKsvbVi_qeiAhEgKPyp1uasen2TtLj7J0L9gTfQY5NoiGaw@mail.gmail.com \
--to=husseydevin@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).