Skip to content

Commit 97fade4

Browse files
author
Edward Thomson
committed
fs_path: use new mktmp to query unicode support
1 parent 53063e7 commit 97fade4

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/fs_path.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,8 @@ int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen)
10401040
return -1;
10411041
}
10421042

1043-
static const char *nfc_file = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D.XXXXXX";
1044-
static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX";
1043+
static const char *nfc_file = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
1044+
static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
10451045

10461046
/* Check if the platform is decomposing unicode data for us. We will
10471047
* emulate core Git and prefer to use precomposed unicode data internally
@@ -1054,39 +1054,42 @@ static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX";
10541054
*/
10551055
bool git_fs_path_does_decompose_unicode(const char *root)
10561056
{
1057-
git_str path = GIT_STR_INIT;
1057+
git_str nfc_path = GIT_STR_INIT;
1058+
git_str nfd_path = GIT_STR_INIT;
10581059
int fd;
10591060
bool found_decomposed = false;
1060-
char tmp[6];
1061+
size_t orig_len;
1062+
const char *trailer;
10611063

10621064
/* Create a file using a precomposed path and then try to find it
10631065
* using the decomposed name. If the lookup fails, then we will mark
10641066
* that we should precompose unicode for this repository.
10651067
*/
1066-
if (git_str_joinpath(&path, root, nfc_file) < 0 ||
1067-
(fd = p_mkstemp(path.ptr)) < 0)
1068+
if (git_str_joinpath(&nfc_path, root, nfc_file) < 0)
1069+
goto done;
1070+
1071+
/* record original path length before trailer */
1072+
orig_len = nfc_path.size;
1073+
1074+
if ((fd = git_futils_mktmp(&nfc_path, nfc_path.ptr, 0666)) < 0)
10681075
goto done;
10691076
p_close(fd);
10701077

1071-
/* record trailing digits generated by mkstemp */
1072-
memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp));
1078+
trailer = nfc_path.ptr + orig_len;
10731079

10741080
/* try to look up as NFD path */
1075-
if (git_str_joinpath(&path, root, nfd_file) < 0)
1081+
if (git_str_joinpath(&nfd_path, root, nfd_file) < 0 ||
1082+
git_str_puts(&nfd_path, trailer) < 0)
10761083
goto done;
1077-
memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
10781084

1079-
found_decomposed = git_fs_path_exists(path.ptr);
1085+
found_decomposed = git_fs_path_exists(nfd_path.ptr);
10801086

10811087
/* remove temporary file (using original precomposed path) */
1082-
if (git_str_joinpath(&path, root, nfc_file) < 0)
1083-
goto done;
1084-
memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
1085-
1086-
(void)p_unlink(path.ptr);
1088+
(void)p_unlink(nfc_path.ptr);
10871089

10881090
done:
1089-
git_str_dispose(&path);
1091+
git_str_dispose(&nfc_path);
1092+
git_str_dispose(&nfd_path);
10901093
return found_decomposed;
10911094
}
10921095

0 commit comments

Comments
 (0)