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
This commit is contained in:
Junio C Hamano 2017-03-30 14:07:15 -07:00
commit 49a8fe8e96
2 changed files with 25 additions and 0 deletions

View File

@ -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;
}

View File

@ -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 )
'