Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Ignore EACCES when doing non-pure globbing



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@xxxxxxxxx>
---
 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




Messages sorted by: Reverse Date, Date, Thread, Author