Skip to content

Commit 435d925

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 42bdd9f commit 435d925

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

compat/mingw.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -735,21 +735,14 @@ int mingw_lstat(const char *file_name, struct stat *buf)
735735
buf->st_gid = 0;
736736
buf->st_uid = 0;
737737
buf->st_nlink = 1;
738-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
738+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
739+
findbuf.dwReserved0);
739740
buf->st_size = fdata.nFileSizeLow |
740741
(((off_t)fdata.nFileSizeHigh)<<32);
741742
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
742743
filetime_to_timespec(&(fdata.ftLastAccessTime), &(buf->st_atim));
743744
filetime_to_timespec(&(fdata.ftLastWriteTime), &(buf->st_mtim));
744745
filetime_to_timespec(&(fdata.ftCreationTime), &(buf->st_ctim));
745-
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
746-
if ((findbuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
747-
(findbuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) {
748-
buf->st_mode = S_IFLNK | S_IREAD;
749-
if (!(findbuf.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
750-
buf->st_mode |= S_IWRITE;
751-
}
752-
}
753746
return 0;
754747
}
755748
error:
@@ -794,7 +787,7 @@ static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
794787
buf->st_gid = 0;
795788
buf->st_uid = 0;
796789
buf->st_nlink = 1;
797-
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
790+
buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes, 0);
798791
buf->st_size = fdata.nFileSizeLow |
799792
(((off_t)fdata.nFileSizeHigh)<<32);
800793
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ static struct fsentry *fseentry_create_entry(struct fscache *cache, struct fsent
180180

181181
fse = fsentry_alloc(cache, list, buf, len);
182182

183-
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes);
184-
fse->u.s.st_size = fdata->EndOfFile.LowPart | (((off_t)fdata->EndOfFile.HighPart) << 32);
183+
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes, fdata->EaSize);
184+
fse->u.s.st_size = S_ISLNK(fse->st_mode) ? MAX_LONG_PATH :
185+
fdata->EndOfFile.LowPart | (((off_t)fdata->EndOfFile.HighPart) << 32);
185186
filetime_to_timespec((FILETIME *)&(fdata->LastAccessTime), &(fse->u.s.st_atim));
186187
filetime_to_timespec((FILETIME *)&(fdata->LastWriteTime), &(fse->u.s.st_mtim));
187188
filetime_to_timespec((FILETIME *)&(fdata->CreationTime), &(fse->u.s.st_ctim));
@@ -580,7 +581,8 @@ static struct dirent *fscache_readdir(DIR *base_dir)
580581
if (!next)
581582
return NULL;
582583
dir->pfsentry = next;
583-
dir->dirent.d_type = S_ISDIR(next->st_mode) ? DT_DIR : DT_REG;
584+
dir->dirent.d_type = S_ISREG(next->st_mode) ? DT_REG :
585+
S_ISDIR(next->st_mode) ? DT_DIR : DT_LNK;
584586
dir->dirent.d_name = (char*) next->name;
585587
return &(dir->dirent);
586588
}

0 commit comments

Comments
 (0)