Skip to content

Commit d854f51

Browse files
kbleesdscho
authored andcommitted
Win32: lstat(): return adequate stat.st_size for symlinks
Git typically doesn't trust the stat.st_size member of symlinks (e.g. see strbuf_readlink()). However, some functions take shortcuts if st_size is 0 (e.g. diff_populate_filespec()). In mingw_lstat() and fscache_lstat(), make sure to return an adequate size. The extra overhead of opening and reading the reparse point to calculate the exact size is not necessary, as git doesn't rely on the value anyway. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0f8867d commit d854f51

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

compat/mingw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ int mingw_lstat(const char *file_name, struct stat *buf)
736736
buf->st_nlink = 1;
737737
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
738738
findbuf.dwReserved0);
739-
buf->st_size = fdata.nFileSizeLow |
740-
(((off_t)fdata.nFileSizeHigh)<<32);
739+
buf->st_size = S_ISLNK(buf->st_mode) ? MAX_LONG_PATH :
740+
fdata.nFileSizeLow | (((off_t) fdata.nFileSizeHigh) << 32);
741741
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
742742
filetime_to_timespec(&(fdata.ftLastAccessTime), &(buf->st_atim));
743743
filetime_to_timespec(&(fdata.ftLastWriteTime), &(buf->st_mtim));

compat/win32/fscache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ static struct fsentry *fseentry_create_entry(struct fsentry *list,
151151

152152
fse->st_mode = file_attr_to_st_mode(fdata->dwFileAttributes,
153153
fdata->dwReserved0);
154-
fse->st_size = (((off64_t) (fdata->nFileSizeHigh)) << 32)
155-
| fdata->nFileSizeLow;
154+
fse->st_size = S_ISLNK(fse->st_mode) ? MAX_LONG_PATH :
155+
fdata->nFileSizeLow | (((off_t) fdata->nFileSizeHigh) << 32);
156156
filetime_to_timespec(&(fdata->ftLastAccessTime), &(fse->st_atim));
157157
filetime_to_timespec(&(fdata->ftLastWriteTime), &(fse->st_mtim));
158158
filetime_to_timespec(&(fdata->ftCreationTime), &(fse->st_ctim));

0 commit comments

Comments
 (0)