Skip to content

Commit 45a475a

Browse files
authored
Merge pull request #3887 from dscho/skip-ownership-test-on-fat
Offer more details to users about the ownership check on FAT32
2 parents 6f00d57 + 75f23a9 commit 45a475a

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

compat/mingw.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3514,6 +3514,22 @@ static PSID get_current_user_sid(void)
35143514
return result;
35153515
}
35163516

3517+
static int acls_supported(const char *path)
3518+
{
3519+
size_t offset = offset_1st_component(path);
3520+
WCHAR wroot[MAX_PATH];
3521+
DWORD file_system_flags;
3522+
3523+
if (offset &&
3524+
xutftowcs_path_ex(wroot, path, MAX_PATH, offset,
3525+
MAX_PATH, 0) > 0 &&
3526+
GetVolumeInformationW(wroot, NULL, 0, NULL, NULL,
3527+
&file_system_flags, NULL, 0))
3528+
return !!(file_system_flags & FILE_PERSISTENT_ACLS);
3529+
3530+
return 0;
3531+
}
3532+
35173533
int is_path_owned_by_current_sid(const char *path)
35183534
{
35193535
WCHAR wpath[MAX_PATH];
@@ -3569,7 +3585,14 @@ int is_path_owned_by_current_sid(const char *path)
35693585
* okay, too.
35703586
*/
35713587
result = 1;
3572-
else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
3588+
else if (IsWellKnownSid(sid, WinWorldSid) &&
3589+
git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0) &&
3590+
!acls_supported(path)) {
3591+
/*
3592+
* On FAT32 volumes, ownership is not actually recorded.
3593+
*/
3594+
warning("'%s' is on a file system that does not record ownership", path);
3595+
} else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
35733596
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
35743597

35753598
if (ConvertSidToStringSidA(sid, &str1))

setup.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,10 +1385,17 @@ const char *setup_git_directory_gently(int *nongit_ok)
13851385
if (!nongit_ok) {
13861386
struct strbuf prequoted = STRBUF_INIT;
13871387
struct strbuf quoted = STRBUF_INIT;
1388+
struct strbuf hint = STRBUF_INIT;
13881389

13891390
#ifdef __MINGW32__
13901391
if (dir.buf[0] == '/')
13911392
strbuf_addstr(&prequoted, "%(prefix)/");
1393+
if (!git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0))
1394+
strbuf_addstr(&hint,
1395+
_("\n\nSet the environment variable "
1396+
"GIT_TEST_DEBUG_UNSAFE_DIRECTORIES=true "
1397+
"and run\n"
1398+
"again for more information."));
13921399
#endif
13931400

13941401
strbuf_add(&prequoted, dir.buf, dir.len);
@@ -1397,8 +1404,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
13971404
die(_("unsafe repository ('%s' is owned by someone else)\n"
13981405
"To add an exception for this directory, call:\n"
13991406
"\n"
1400-
"\tgit config --global --add safe.directory %s"),
1401-
dir.buf, quoted.buf);
1407+
"\tgit config --global --add safe.directory %s%s"),
1408+
dir.buf, quoted.buf, hint.buf);
14021409
}
14031410
*nongit_ok = 1;
14041411
break;

0 commit comments

Comments
 (0)