Skip to content

Commit d5b0f53

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 37600a2 commit d5b0f53

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

compat/mingw.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -789,21 +789,14 @@ int mingw_lstat(const char *file_name, struct stat *buf)
789789
buf->st_gid = 0;
790790
buf->st_uid = 0;
791791
buf->st_nlink = 1;
792-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
792+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
793+
findbuf.dwReserved0);
793794
buf->st_size = fdata.nFileSizeLow |
794795
(((off_t)fdata.nFileSizeHigh)<<32);
795796
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
796797
filetime_to_timespec(&(fdata.ftLastAccessTime), &(buf->st_atim));
797798
filetime_to_timespec(&(fdata.ftLastWriteTime), &(buf->st_mtim));
798799
filetime_to_timespec(&(fdata.ftCreationTime), &(buf->st_ctim));
799-
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
800-
if ((findbuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
801-
(findbuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) {
802-
buf->st_mode = S_IFLNK | S_IREAD;
803-
if (!(findbuf.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
804-
buf->st_mode |= S_IWRITE;
805-
}
806-
}
807800
return 0;
808801
}
809802
error:
@@ -848,7 +841,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
848841
buf->st_gid = 0;
849842
buf->st_uid = 0;
850843
buf->st_nlink = 1;
851-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
844+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0);
852845
buf->st_size = fdata.nFileSizeLow |
853846
(((off_t)fdata.nFileSizeHigh)<<32);
854847
buf->st_dev = buf->st_rdev = 0; /* not used by Git */

compat/win32.h

Lines changed: 4 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1515
xwcstoutf(ent->d_name, fdata->cFileName, MAX_PATH * 3);
1616

1717
/* Set file type, based on WIN32_FIND_DATA */
18-
if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
18+
if ((fdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
19+
&& fdata->dwReserved0 == IO_REPARSE_TAG_SYMLINK)
20+
ent->d_type = DT_LNK;
21+
else if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1922
ent->d_type = DT_DIR;
2023
else
2124
ent->d_type = DT_REG;

compat/win32/fscache.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,13 @@ static struct fsentry *fseentry_create_entry(struct fscache *cache,
194194
fdata->FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT ?
195195
fdata->EaSize : 0;
196196

197-
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes);
198-
fse->dirent.d_type = S_ISDIR(fse->st_mode) ? DT_DIR : DT_REG;
199-
fse->u.s.st_size = fdata->EndOfFile.LowPart |
200-
(((off_t)fdata->EndOfFile.HighPart) << 32);
197+
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes,
198+
fdata->EaSize);
199+
fse->dirent.d_type = S_ISREG(fse->st_mode) ? DT_REG :
200+
S_ISDIR(fse->st_mode) ? DT_DIR : DT_LNK;
201+
fse->u.s.st_size = S_ISLNK(fse->st_mode) ? MAX_LONG_PATH :
202+
fdata->EndOfFile.LowPart |
203+
(((off_t)fdata->EndOfFile.HighPart) << 32);
201204
filetime_to_timespec((FILETIME *)&(fdata->LastAccessTime),
202205
&(fse->u.s.st_atim));
203206
filetime_to_timespec((FILETIME *)&(fdata->LastWriteTime),

0 commit comments

Comments
 (0)