Skip to content

Commit 7c83470

Browse files
dschogitster
authored andcommitted
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. This addresses git-for-windows#3886 Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e883e04 commit 7c83470

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
@@ -2674,6 +2674,21 @@ static PSID get_current_user_sid(void)
26742674
return result;
26752675
}
26762676

2677+
static int acls_supported(const char *path)
2678+
{
2679+
size_t offset = offset_1st_component(path);
2680+
WCHAR wroot[MAX_PATH];
2681+
DWORD file_system_flags;
2682+
2683+
if (offset &&
2684+
xutftowcsn(wroot, path, MAX_PATH, offset) > 0 &&
2685+
GetVolumeInformationW(wroot, NULL, 0, NULL, NULL,
2686+
&file_system_flags, NULL, 0))
2687+
return !!(file_system_flags & FILE_PERSISTENT_ACLS);
2688+
2689+
return 0;
2690+
}
2691+
26772692
int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
26782693
{
26792694
WCHAR wpath[MAX_PATH];
@@ -2721,7 +2736,15 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
27212736
IsValidSid(current_user_sid) &&
27222737
EqualSid(sid, current_user_sid))
27232738
result = 1;
2724-
else if (report) {
2739+
else if (report &&
2740+
IsWellKnownSid(sid, WinWorldSid) &&
2741+
!acls_supported(path)) {
2742+
/*
2743+
* On FAT32 volumes, ownership is not actually recorded.
2744+
*/
2745+
strbuf_addf(report, "'%s' is on a file system that does"
2746+
"not record ownership\n", path);
2747+
} else if (report) {
27252748
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
27262749

27272750
if (ConvertSidToStringSidA(sid, &str1))

0 commit comments

Comments
 (0)