Commit 40b289d73058601f96681c0e1048fce46c1751b1

Stefan Sperling 2019-09-07T12:05:27

make 'got status' ignore inaccessible directories (reported by semarie)

diff --git a/lib/fileindex.c b/lib/fileindex.c
index 696ab23..05c0896 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -926,6 +926,10 @@ walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
 
 		subdir = opendir(subdirpath);
 		if (subdir == NULL) {
+			if (errno == EACCES) {
+				*next = TAILQ_NEXT(dle, entry);
+				return NULL;
+			}
 			err = got_error_from_errno2("opendir", subdirpath);
 			free(subpath);
 			free(subdirpath);
diff --git a/lib/worktree.c b/lib/worktree.c
index b6130cb..1c38979 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2451,7 +2451,7 @@ add_ignores(struct got_pathlist_head *ignores, const char *root_path,
 
 	ignoresfile = fopen(ignorespath, "r");
 	if (ignoresfile == NULL) {
-		if (errno != ENOENT)
+		if (errno != ENOENT && errno != EACCES)
 			err = got_error_from_errno2("fopen",
 			    ignorespath);
 	} else
@@ -2541,7 +2541,7 @@ worktree_status(struct got_worktree *worktree, const char *path,
 
 	workdir = opendir(ondisk_path);
 	if (workdir == NULL) {
-		if (errno != ENOTDIR && errno != ENOENT)
+		if (errno != ENOTDIR && errno != ENOENT && errno != EACCES)
 			err = got_error_from_errno2("opendir", ondisk_path);
 		else
 			err = report_single_file_status(path, ondisk_path,
diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh
index 99766ac..5fde224 100755
--- a/regress/cmdline/status.sh
+++ b/regress/cmdline/status.sh
@@ -33,6 +33,7 @@ function test_status_basic {
 	touch $testroot/wt/beta
 	echo "new file" > $testroot/wt/new
 	(cd $testroot/wt && got add new >/dev/null)
+	mkdir -m 0000 $testroot/wt/bar
 
 	echo 'M  alpha' > $testroot/stdout.expected
 	echo 'D  beta' >> $testroot/stdout.expected
@@ -47,6 +48,8 @@ function test_status_basic {
 	if [ "$ret" != "0" ]; then
 		diff -u $testroot/stdout.expected $testroot/stdout
 	fi
+	chmod 700 $testroot/wt/bar
+	rmdir $testroot/wt/bar
 	test_done "$testroot" "$ret"
 }