Skip to content

Commit b6b8e71

Browse files
kbleesdscho
authored andcommitted
Win32: 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 89302a1 commit b6b8e71

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

compat/mingw.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -689,21 +689,14 @@ int mingw_lstat(const char *file_name, struct stat *buf)
689689
buf->st_gid = 0;
690690
buf->st_uid = 0;
691691
buf->st_nlink = 1;
692-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
692+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
693+
findbuf.dwReserved0);
693694
buf->st_size = fdata.nFileSizeLow |
694695
(((off_t)fdata.nFileSizeHigh)<<32);
695696
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
696697
filetime_to_timespec(&(fdata.ftLastAccessTime), &(buf->st_atim));
697698
filetime_to_timespec(&(fdata.ftLastWriteTime), &(buf->st_mtim));
698699
filetime_to_timespec(&(fdata.ftCreationTime), &(buf->st_ctim));
699-
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
700-
if ((findbuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
701-
(findbuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) {
702-
buf->st_mode = S_IFLNK | S_IREAD;
703-
if (!(findbuf.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
704-
buf->st_mode |= S_IWRITE;
705-
}
706-
}
707700
return 0;
708701
}
709702
error:
@@ -748,7 +741,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
748741
buf->st_gid = 0;
749742
buf->st_uid = 0;
750743
buf->st_nlink = 1;
751-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
744+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0);
752745
buf->st_size = fdata.nFileSizeLow |
753746
(((off_t)fdata.nFileSizeHigh)<<32);
754747
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
@@ -16,7 +16,10 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1616
xwcstoutf(ent->d_name, fdata->cFileName, MAX_PATH * 3);
1717

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

compat/win32/fscache.c

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

150150
fse = fsentry_alloc(list, buf, len);
151151

152-
fse->st_mode = file_attr_to_st_mode(fdata->dwFileAttributes);
152+
fse->st_mode = file_attr_to_st_mode(fdata->dwFileAttributes,
153+
fdata->dwReserved0);
153154
fse->st_size = (((off64_t) (fdata->nFileSizeHigh)) << 32)
154155
| fdata->nFileSizeLow;
155156
filetime_to_timespec(&(fdata->ftLastAccessTime), &(fse->st_atim));
@@ -442,7 +443,8 @@ static struct dirent *fscache_readdir(DIR *base_dir)
442443
if (!next)
443444
return NULL;
444445
dir->pfsentry = next;
445-
dir->dirent.d_type = S_ISDIR(next->st_mode) ? DT_DIR : DT_REG;
446+
dir->dirent.d_type = S_ISREG(next->st_mode) ? DT_REG :
447+
S_ISDIR(next->st_mode) ? DT_DIR : DT_LNK;
446448
dir->dirent.d_name = (char*) next->name;
447449
return &(dir->dirent);
448450
}

0 commit comments

Comments
 (0)