Skip to content

Commit 606e325

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 172c62c commit 606e325

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
@@ -817,21 +817,14 @@ int mingw_lstat(const char *file_name, struct stat *buf)
817817
buf->st_gid = 0;
818818
buf->st_uid = 0;
819819
buf->st_nlink = 1;
820-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
820+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
821+
findbuf.dwReserved0);
821822
buf->st_size = fdata.nFileSizeLow |
822823
(((off_t)fdata.nFileSizeHigh)<<32);
823824
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
824825
filetime_to_timespec(&(fdata.ftLastAccessTime), &(buf->st_atim));
825826
filetime_to_timespec(&(fdata.ftLastWriteTime), &(buf->st_mtim));
826827
filetime_to_timespec(&(fdata.ftCreationTime), &(buf->st_ctim));
827-
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
828-
if ((findbuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
829-
(findbuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) {
830-
buf->st_mode = S_IFLNK | S_IREAD;
831-
if (!(findbuf.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
832-
buf->st_mode |= S_IWRITE;
833-
}
834-
}
835828
return 0;
836829
}
837830
error:
@@ -876,7 +869,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
876869
buf->st_gid = 0;
877870
buf->st_uid = 0;
878871
buf->st_nlink = 1;
879-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
872+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0);
880873
buf->st_size = fdata.nFileSizeLow |
881874
(((off_t)fdata.nFileSizeHigh)<<32);
882875
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
@@ -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

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

202-
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes);
203-
fse->dirent.d_type = S_ISDIR(fse->st_mode) ? DT_DIR : DT_REG;
204-
fse->u.s.st_size = fdata->EndOfFile.LowPart |
205-
(((off_t)fdata->EndOfFile.HighPart) << 32);
202+
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes,
203+
fdata->EaSize);
204+
fse->dirent.d_type = S_ISREG(fse->st_mode) ? DT_REG :
205+
S_ISDIR(fse->st_mode) ? DT_DIR : DT_LNK;
206+
fse->u.s.st_size = S_ISLNK(fse->st_mode) ? MAX_LONG_PATH :
207+
fdata->EndOfFile.LowPart |
208+
(((off_t)fdata->EndOfFile.HighPart) << 32);
206209
filetime_to_timespec((FILETIME *)&(fdata->LastAccessTime),
207210
&(fse->u.s.st_atim));
208211
filetime_to_timespec((FILETIME *)&(fdata->LastWriteTime),

0 commit comments

Comments
 (0)