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 https://github.com/git-for-windows/git/issues/3886 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 8, 2022 at 13:27 UTC 7c83470e64eadab74689427fcd95e72f0a772ab5
1 file changed +24 -1
compat/mingw.c
+24 -1
@@ -2674,6 +2674,21 @@ static PSID get_current_user_sid(void)
2674 return result;
2675 }
2676
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 +
2692 int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
2693 {
2694 WCHAR wpath[MAX_PATH];
@@ -2721,7 +2736,15 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
2736 IsValidSid(current_user_sid) &&
2737 EqualSid(sid, current_user_sid))
2738 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) {
2748 LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
2749
2750 if (ConvertSidToStringSidA(sid, &str1))