Skip to content

Commit 41c6ef4

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]>
1 parent ac5c42e commit 41c6ef4

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
@@ -585,8 +585,8 @@ int mingw_lstat(const char *file_name, struct stat *buf)
585585
buf->st_nlink = 1;
586586
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
587587
findbuf.dwReserved0);
588-
buf->st_size = fdata.nFileSizeLow |
589-
(((off_t)fdata.nFileSizeHigh)<<32);
588+
buf->st_size = S_ISLNK(buf->st_mode) ? MAX_LONG_PATH :
589+
fdata.nFileSizeLow | (((off_t) fdata.nFileSizeHigh) << 32);
590590
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
591591
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
592592
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));

compat/win32/fscache.c

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

150150
fse->st_mode = file_attr_to_st_mode(fdata->dwFileAttributes,
151151
fdata->dwReserved0);
152-
fse->st_size = (((off64_t) (fdata->nFileSizeHigh)) << 32)
153-
| fdata->nFileSizeLow;
152+
fse->st_size = S_ISLNK(fse->st_mode) ? MAX_LONG_PATH :
153+
fdata->nFileSizeLow | (((off_t) fdata->nFileSizeHigh) << 32);
154154
fse->st_atime = filetime_to_time_t(&(fdata->ftLastAccessTime));
155155
fse->st_mtime = filetime_to_time_t(&(fdata->ftLastWriteTime));
156156
fse->st_ctime = filetime_to_time_t(&(fdata->ftCreationTime));

0 commit comments

Comments
 (0)