Skip to content

Commit bb2a754

Browse files
committed
path: use fstatat instead of lstat
1 parent f7d1152 commit bb2a754

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/path.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
#include "win32/w32_util.h"
1616
#include "win32/version.h"
1717
#else
18+
#include <fcntl.h>
1819
#include <dirent.h>
20+
#include <sys/stat.h>
21+
#include <sys/types.h>
1922
#endif
2023
#include <stdio.h>
2124
#include <ctype.h>
@@ -1398,6 +1401,8 @@ int git_path_diriter_next(git_path_diriter *diriter)
13981401
if (git_buf_oom(&diriter->path))
13991402
return -1;
14001403

1404+
diriter->d_type = de->d_type;
1405+
14011406
return error;
14021407
}
14031408

@@ -1429,9 +1434,14 @@ int git_path_diriter_fullpath(
14291434

14301435
int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
14311436
{
1437+
const char *fname;
1438+
14321439
assert(out && diriter);
14331440

1434-
return git_path_lstat(diriter->path.ptr, out);
1441+
fname = diriter->path.ptr + diriter->parent_len;
1442+
if (*fname == '/') ++fname;
1443+
1444+
return fstatat(dirfd(diriter->dir), fname, out, AT_SYMLINK_NOFOLLOW);
14351445
}
14361446

14371447
void git_path_diriter_free(git_path_diriter *diriter)

src/path.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ struct git_path_diriter
482482
{
483483
git_buf path;
484484
size_t parent_len;
485+
unsigned char d_type;
485486

486487
unsigned int flags;
487488

0 commit comments

Comments
 (0)