From 272952d151cab5e5abecc5168e3430237b0c9090 Mon Sep 17 00:00:00 2001 From: lixungeng Date: Sat, 28 Oct 2023 03:06:49 +0800 Subject: [PATCH] fix wsl mode bits bug in subdir 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. Signed-off-by: lixungeng --- compat/win32/fscache.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/compat/win32/fscache.c b/compat/win32/fscache.c index 77afa2331de391..be4e76ad48fdc6 100644 --- a/compat/win32/fscache.c +++ b/compat/win32/fscache.c @@ -238,9 +238,20 @@ static struct fsentry *fseentry_create_entry(struct fscache *cache, &(fse->u.s.st_mtim)); filetime_to_timespec((FILETIME *)&(fdata->CreationTime), &(fse->u.s.st_ctim)); - if (fdata->EaSize > 0 && are_wsl_compatible_mode_bits_enabled()) { - copy_wsl_mode_bits_from_disk(fdata->FileName, - fdata->FileNameLength / sizeof(wchar_t), &fse->st_mode); + if (fdata->EaSize > 0 && + sizeof(buf) >= (list ? list->len+1 : 0) + fse->len+1 && + are_wsl_compatible_mode_bits_enabled()) { + size_t off = 0; + wchar_t wpath[MAX_LONG_PATH]; + if (list) { + memcpy(buf, list->dirent.d_name, list->len); + buf[list->len] = '/'; + off = list->len + 1; + } + memcpy(buf + off, fse->dirent.d_name, fse->len); + buf[off + fse->len] = '\0'; + if (xutftowcs_long_path(wpath, buf) >= 0) + copy_wsl_mode_bits_from_disk(wpath, -1, &fse->st_mode); } return fse;