Skip to content

Commit 49a8fe8

Browse files
committed
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
2 parents 3736c92 + a54e938 commit 49a8fe8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

strbuf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,17 @@ int strbuf_getcwd(struct strbuf *sb)
449449
strbuf_setlen(sb, strlen(sb->buf));
450450
return 0;
451451
}
452+
453+
/*
454+
* If getcwd(3) is implemented as a syscall that falls
455+
* back to a regular lookup using readdir(3) etc. then
456+
* we may be able to avoid EACCES by providing enough
457+
* space to the syscall as it's not necessarily bound
458+
* to the same restrictions as the fallback.
459+
*/
460+
if (errno == EACCES && guessed_len < PATH_MAX)
461+
continue;
462+
452463
if (errno != ERANGE)
453464
break;
454465
}

t/t0001-init.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ test_expect_success 'init with separate gitdir' '
315315
test_path_is_dir realgitdir/refs
316316
'
317317

318+
test_expect_success 'init in long base path' '
319+
# exceed initial buffer size of strbuf_getcwd()
320+
component=123456789abcdef &&
321+
test_when_finished "chmod 0700 $component; rm -rf $component" &&
322+
p31=$component/$component &&
323+
p127=$p31/$p31/$p31/$p31 &&
324+
mkdir -p $p127 &&
325+
chmod 0111 $component &&
326+
(
327+
cd $p127 &&
328+
git init newdir
329+
)
330+
'
331+
318332
test_expect_success 're-init on .git file' '
319333
( cd newdir && git init )
320334
'

0 commit comments

Comments
 (0)