Skip to content

Commit 28481d4

Browse files
authored
[bugfix] fix wsl mode bits error in subdir (#4660)
Support for wsl mode bits was previously added to git, but there was a bug because the filenames provided by fscache did not contain paths. This commit fixes the issue. The previous feature is added in PR #4438, but at that time I didn't tested so much. Sorry to have this bug. To test this feature, set core.wslcompat to ture and core.filemode to true and make sure repo is on NTFS.
2 parents 059f0c9 + 15bcde9 commit 28481d4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

compat/win32/fscache.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,20 @@ static struct fsentry *fseentry_create_entry(struct fscache *cache,
238238
&(fse->u.s.st_mtim));
239239
filetime_to_timespec((FILETIME *)&(fdata->CreationTime),
240240
&(fse->u.s.st_ctim));
241-
if (fdata->EaSize > 0 && are_wsl_compatible_mode_bits_enabled()) {
242-
copy_wsl_mode_bits_from_disk(fdata->FileName,
243-
fdata->FileNameLength / sizeof(wchar_t), &fse->st_mode);
241+
if (fdata->EaSize > 0 &&
242+
sizeof(buf) >= (list ? list->len+1 : 0) + fse->len+1 &&
243+
are_wsl_compatible_mode_bits_enabled()) {
244+
size_t off = 0;
245+
wchar_t wpath[MAX_LONG_PATH];
246+
if (list && list->len) {
247+
memcpy(buf, list->dirent.d_name, list->len);
248+
buf[list->len] = '/';
249+
off = list->len + 1;
250+
}
251+
memcpy(buf + off, fse->dirent.d_name, fse->len);
252+
buf[off + fse->len] = '\0';
253+
if (xutftowcs_long_path(wpath, buf) >= 0)
254+
copy_wsl_mode_bits_from_disk(wpath, -1, &fse->st_mode);
244255
}
245256

246257
return fse;

0 commit comments

Comments
 (0)