Skip to content

Commit 75f23a9

Browse files
committed
mingw: be more informative when ownership check fails on FAT32
The FAT file system has no concept of ACLs. Therefore, it cannot store any ownership information anyway, and the `GetNamedSecurityInfoW()` call pretends that everything is owned "by the world". Let's special-case that scenario and tell the user what's going on, at least when they set `GIT_TEST_DEBUG_UNSAFE_DIRECTORIES`. This addresses git-for-windows#3886 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f0db573 commit 75f23a9

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

compat/mingw.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,22 @@ static PSID get_current_user_sid(void)
34863486
return result;
34873487
}
34883488

3489+
static int acls_supported(const char *path)
3490+
{
3491+
size_t offset = offset_1st_component(path);
3492+
WCHAR wroot[MAX_PATH];
3493+
DWORD file_system_flags;
3494+
3495+
if (offset &&
3496+
xutftowcs_path_ex(wroot, path, MAX_PATH, offset,
3497+
MAX_PATH, 0) > 0 &&
3498+
GetVolumeInformationW(wroot, NULL, 0, NULL, NULL,
3499+
&file_system_flags, NULL, 0))
3500+
return !!(file_system_flags & FILE_PERSISTENT_ACLS);
3501+
3502+
return 0;
3503+
}
3504+
34893505
int is_path_owned_by_current_sid(const char *path)
34903506
{
34913507
WCHAR wpath[MAX_PATH];
@@ -3541,7 +3557,14 @@ int is_path_owned_by_current_sid(const char *path)
35413557
* okay, too.
35423558
*/
35433559
result = 1;
3544-
else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
3560+
else if (IsWellKnownSid(sid, WinWorldSid) &&
3561+
git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0) &&
3562+
!acls_supported(path)) {
3563+
/*
3564+
* On FAT32 volumes, ownership is not actually recorded.
3565+
*/
3566+
warning("'%s' is on a file system that does not record ownership", path);
3567+
} else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
35453568
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
35463569

35473570
if (ConvertSidToStringSidA(sid, &str1))

0 commit comments

Comments
 (0)