Skip to content

Commit f9df7b6

Browse files
Edward Thomsonethomson
authored andcommitted
checkout tests: emulate p_realpath poorly on Win32
1 parent 8d65523 commit f9df7b6

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

tests/checkout/icase.c

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "git2/checkout.h"
44
#include "path.h"
55

6+
#ifdef GIT_WIN32
7+
# include <Windows.h>
8+
#endif
9+
610
static git_repository *repo;
711
static git_object *obj;
812
static git_checkout_options checkout_opts;
@@ -26,12 +30,71 @@ void test_checkout_icase__cleanup(void)
2630
cl_git_sandbox_cleanup();
2731
}
2832

33+
static char *p_realpath(const char *in)
34+
{
35+
#ifdef GIT_WIN32
36+
/*
37+
38+
HANDLE fh, mh;
39+
HINSTANCE psapi;
40+
BY_HANDLE_FILE_INFORMATION fi;
41+
void *map;
42+
char *filename;
43+
size_t filename_len = 1024;
44+
45+
typedef DWORD (__stdcall *getmappedfilename)(HANDLE, LPVOID, LPTSTR, DWORD);
46+
getmappedfilename getfunc;
47+
48+
cl_assert(filename = malloc(filename_len));
49+
50+
cl_win32_pass(psapi = LoadLibrary("psapi.dll"));
51+
cl_win32_pass(getfunc = (getmappedfilename)GetProcAddress(psapi, "GetMappedFileNameA"));
52+
53+
cl_win32_pass(fh = CreateFileA(in, GENERIC_READ, FILE_SHARE_READ,
54+
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
55+
cl_win32_pass(mh = CreateFileMapping(fh, NULL, PAGE_READONLY, 0, 1, NULL));
56+
57+
cl_win32_pass(map = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, 1));
58+
59+
cl_win32_pass(getfunc(GetCurrentProcess(), map, filename, filename_len));
60+
61+
UnmapViewOfFile(map);
62+
CloseHandle(mh);
63+
CloseHandle(fh);
64+
*/
65+
66+
HANDLE fh;
67+
HINSTANCE kerneldll;
68+
char *filename;
69+
70+
typedef DWORD (__stdcall *getfinalpathname)(HANDLE, LPSTR, DWORD, DWORD);
71+
getfinalpathname getfinalpathfn;
72+
73+
cl_assert(filename = malloc(MAX_PATH));
74+
cl_win32_pass(kerneldll = LoadLibrary("kernel32.dll"));
75+
cl_win32_pass(getfinalpathfn = (getfinalpathname)GetProcAddress(kerneldll, "GetFinalPathNameByHandleA"));
76+
77+
cl_win32_pass(fh = CreateFileA(in, FILE_READ_ATTRIBUTES | STANDARD_RIGHTS_READ, FILE_SHARE_READ,
78+
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL));
79+
80+
cl_win32_pass(getfinalpathfn(fh, filename, MAX_PATH, VOLUME_NAME_DOS));
81+
82+
CloseHandle(fh);
83+
84+
git_path_mkposix(filename);
85+
86+
return filename;
87+
#else
88+
return realpath(in, NULL);
89+
#endif
90+
}
91+
2992
static void assert_name_is(const char *expected)
3093
{
3194
char *actual;
3295
size_t actual_len, expected_len, start;
3396

34-
cl_assert(actual = realpath(expected, NULL));
97+
cl_assert(actual = p_realpath(expected));
3598

3699
expected_len = strlen(expected);
37100
actual_len = strlen(actual);

0 commit comments

Comments
 (0)