Skip to content

Commit 0f8867d

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 cec2b95 commit 0f8867d

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
@@ -734,21 +734,14 @@ int mingw_lstat(const char *file_name, struct stat *buf)
734734
buf->st_gid = 0;
735735
buf->st_uid = 0;
736736
buf->st_nlink = 1;
737-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
737+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
738+
findbuf.dwReserved0);
738739
buf->st_size = fdata.nFileSizeLow |
739740
(((off_t)fdata.nFileSizeHigh)<<32);
740741
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
741742
filetime_to_timespec(&(fdata.ftLastAccessTime), &(buf->st_atim));
742743
filetime_to_timespec(&(fdata.ftLastWriteTime), &(buf->st_mtim));
743744
filetime_to_timespec(&(fdata.ftCreationTime), &(buf->st_ctim));
744-
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
745-
if ((findbuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
746-
(findbuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) {
747-
buf->st_mode = S_IFLNK | S_IREAD;
748-
if (!(findbuf.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
749-
buf->st_mode |= S_IWRITE;
750-
}
751-
}
752745
return 0;
753746
}
754747
error:
@@ -793,7 +786,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
793786
buf->st_gid = 0;
794787
buf->st_uid = 0;
795788
buf->st_nlink = 1;
796-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
789+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0);
797790
buf->st_size = fdata.nFileSizeLow |
798791
(((off_t)fdata.nFileSizeHigh)<<32);
799792
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)