Skip to content

Commit 797b60f

Browse files
kbleesdscho
authored andcommitted
mingw: teach fscache and dirent about symlinks
Move S_IFLNK detection to file_attr_to_st_mode() and reuse it in fscache. Implement DT_LNK detection in dirent.c and the fscache readdir version. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 04ac44d commit 797b60f

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

compat/mingw.c

+3-10
Original file line numberDiff line numberDiff line change
@@ -894,21 +894,14 @@ int mingw_lstat(const char *file_name, struct stat *buf)
894894
buf->st_gid = 0;
895895
buf->st_uid = 0;
896896
buf->st_nlink = 1;
897-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
897+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
898+
findbuf.dwReserved0);
898899
buf->st_size = fdata.nFileSizeLow |
899900
(((off_t)fdata.nFileSizeHigh)<<32);
900901
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
901902
filetime_to_timespec(&(fdata.ftLastAccessTime), &(buf->st_atim));
902903
filetime_to_timespec(&(fdata.ftLastWriteTime), &(buf->st_mtim));
903904
filetime_to_timespec(&(fdata.ftCreationTime), &(buf->st_ctim));
904-
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
905-
if ((findbuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
906-
(findbuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) {
907-
buf->st_mode = S_IFLNK | S_IREAD;
908-
if (!(findbuf.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
909-
buf->st_mode |= S_IWRITE;
910-
}
911-
}
912905
return 0;
913906
}
914907
error:
@@ -953,7 +946,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
953946
buf->st_gid = 0;
954947
buf->st_uid = 0;
955948
buf->st_nlink = 1;
956-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
949+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0);
957950
buf->st_size = fdata.nFileSizeLow |
958951
(((off_t)fdata.nFileSizeHigh)<<32);
959952
buf->st_dev = buf->st_rdev = 0; /* not used by Git */

compat/win32.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
#include <windows.h>
77
#endif
88

9-
static inline int file_attr_to_st_mode (DWORD attr)
9+
static inline int file_attr_to_st_mode (DWORD attr, DWORD tag)
1010
{
1111
int fMode = S_IREAD;
12-
if (attr & FILE_ATTRIBUTE_DIRECTORY)
12+
if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) && tag == IO_REPARSE_TAG_SYMLINK)
13+
fMode |= S_IFLNK;
14+
else if (attr & FILE_ATTRIBUTE_DIRECTORY)
1315
fMode |= S_IFDIR;
1416
else
1517
fMode |= S_IFREG;

compat/win32/dirent.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1818
xwcstoutf(ent->d_name, fdata->cFileName, MAX_PATH * 3);
1919

2020
/* Set file type, based on WIN32_FIND_DATA */
21-
if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
21+
if ((fdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
22+
&& fdata->dwReserved0 == IO_REPARSE_TAG_SYMLINK)
23+
ent->d_type = DT_LNK;
24+
else if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2225
ent->d_type = DT_DIR;
2326
else
2427
ent->d_type = DT_REG;

compat/win32/fscache.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,13 @@ static struct fsentry *fseentry_create_entry(struct fscache *cache,
202202
fdata->FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT ?
203203
fdata->EaSize : 0;
204204

205-
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes);
206-
fse->dirent.d_type = S_ISDIR(fse->st_mode) ? DT_DIR : DT_REG;
207-
fse->u.s.st_size = fdata->EndOfFile.LowPart |
208-
(((off_t)fdata->EndOfFile.HighPart) << 32);
205+
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes,
206+
fdata->EaSize);
207+
fse->dirent.d_type = S_ISREG(fse->st_mode) ? DT_REG :
208+
S_ISDIR(fse->st_mode) ? DT_DIR : DT_LNK;
209+
fse->u.s.st_size = S_ISLNK(fse->st_mode) ? MAX_LONG_PATH :
210+
fdata->EndOfFile.LowPart |
211+
(((off_t)fdata->EndOfFile.HighPart) << 32);
209212
filetime_to_timespec((FILETIME *)&(fdata->LastAccessTime),
210213
&(fse->u.s.st_atim));
211214
filetime_to_timespec((FILETIME *)&(fdata->LastWriteTime),

0 commit comments

Comments
 (0)