zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Ignore EACCES when doing non-pure globbing
@ 2021-01-12 22:42 Devin Hussey
  2021-01-12 22:48 ` Devin Hussey
  2021-01-12 23:47 ` Lawrence Velázquez
  0 siblings, 2 replies; 9+ messages in thread
From: Devin Hussey @ 2021-01-12 22:42 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-01-13  3:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 22:42 [PATCH] Ignore EACCES when doing non-pure globbing Devin Hussey
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

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).