Skip to content

Commit a29014e

Browse files
dschoGit for Windows Build Agent
authored andcommitted
fscache: compute correct symlink size in lstat()
In #2637, we fixed a bug where symbolic links' target path sizes were recorded incorrectly in the index. However, we did so only in `mingw_lstat()` but not in `fscache_lstat()`. Meaning: in code paths where the FSCache feature is enabled, Git _still_ got the wrong idea if the symbolic link target's length. Let's fix this. Note: as the FSCache feature reads in whole swaths of directory entries in batch mode, even if metadata for only one of them might be required, we save the expensive `CreateFile()` call that is required to compute the symbolic link target's length to the `fscache_lstat()` call. This fixes #2653. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 79fa9d1 commit a29014e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compat/win32/fscache.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,18 @@ int fscache_lstat(const char *filename, struct stat *st)
596596
if (!fse)
597597
return -1;
598598

599+
/*
600+
* Special case symbolic links: FindFirstFile()/FindNextFile() did not
601+
* provide us with the length of the target path.
602+
*/
603+
if (fse->u.s.st_size == MAX_LONG_PATH && S_ISLNK(fse->st_mode)) {
604+
char buf[MAX_LONG_PATH];
605+
int len = readlink(filename, buf, sizeof(buf) - 1);
606+
607+
if (len > 0)
608+
fse->u.s.st_size = len;
609+
}
610+
599611
/* copy stat data */
600612
st->st_ino = 0;
601613
st->st_gid = 0;

0 commit comments

Comments
 (0)