summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-03-30 14:07:15 -0700
committerJunio C Hamano <gitster@pobox.com>2017-03-30 14:07:15 -0700
commit49a8fe8e962ed929cf5bed5520e581025f5bfe9a (patch)
treead3ea9fb0b4653e801eb51390c5695e26201de13
parent3736c925580f678f601d670983f7f6cda791d108 (diff)
parenta54e938e5b53c76ebcd5c068a4f74739c1c68bac (diff)
downloadgit-49a8fe8e962ed929cf5bed5520e581025f5bfe9a.tar.gz
Merge branch 'rs/freebsd-getcwd-workaround'
FreeBSD implementation of getcwd(3) behaved differently when an intermediate directory is unreadable/unsearchable depending on the length of the buffer provided, which our strbuf_getcwd() was not aware of. strbuf_getcwd() has been taught to cope with it better. * rs/freebsd-getcwd-workaround: strbuf: support long paths w/o read rights in strbuf_getcwd() on FreeBSD
-rw-r--r--strbuf.c11
-rwxr-xr-xt/t0001-init.sh14
2 files changed, 25 insertions, 0 deletions
diff --git a/strbuf.c b/strbuf.c
index ace58e7367..00457940cf 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -449,6 +449,17 @@ int strbuf_getcwd(struct strbuf *sb)
strbuf_setlen(sb, strlen(sb->buf));
return 0;
}
+
+ /*
+ * If getcwd(3) is implemented as a syscall that falls
+ * back to a regular lookup using readdir(3) etc. then
+ * we may be able to avoid EACCES by providing enough
+ * space to the syscall as it's not necessarily bound
+ * to the same restrictions as the fallback.
+ */
+ if (errno == EACCES && guessed_len < PATH_MAX)
+ continue;
+
if (errno != ERANGE)
break;
}
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index e424de5363..c4814d248f 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -315,6 +315,20 @@ test_expect_success 'init with separate gitdir' '
test_path_is_dir realgitdir/refs
'
+test_expect_success 'init in long base path' '
+ # exceed initial buffer size of strbuf_getcwd()
+ component=123456789abcdef &&
+ test_when_finished "chmod 0700 $component; rm -rf $component" &&
+ p31=$component/$component &&
+ p127=$p31/$p31/$p31/$p31 &&
+ mkdir -p $p127 &&
+ chmod 0111 $component &&
+ (
+ cd $p127 &&
+ git init newdir
+ )
+'
+
test_expect_success 're-init on .git file' '
( cd newdir && git init )
'