Clone: non-empty-dir test, now for Win32.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/src/clone.c b/src/clone.c
index 7790049..9e6f58d 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -6,7 +6,10 @@
*/
#include <assert.h>
+
+#ifndef GIT_WIN32
#include <dirent.h>
+#endif
#include "git2/clone.h"
#include "git2/remote.h"
@@ -184,8 +187,15 @@ static bool is_dot_or_dotdot(const char *name)
/* TODO: p_opendir, p_closedir */
static bool path_is_okay(const char *path)
{
- DIR *dir;
+#ifdef GIT_WIN32
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ wchar_t *wbuf;
+ WIN32_FIND_DATAW ffd;
+#else
+ DIR *dir = NULL;
struct dirent *e;
+#endif
+
bool retval = true;
/* The path must either not exist, or be an empty directory */
@@ -197,6 +207,16 @@ static bool path_is_okay(const char *path)
return false;
}
+#ifdef GIT_WIN32
+ wbuf = gitwin_to_utf16(path);
+ gitwin_append_utf16(wbuf, "\\*", 2);
+ hFind = FindFirstFileW(wbuf, &ffd);
+ if (INVALID_HANDLE_VALUE != hFind) {
+ retval = false;
+ FindClose(hFind);
+ }
+ git__free(wbuf);
+#else
dir = opendir(path);
if (!dir) {
giterr_set(GITERR_OS, "Couldn't open '%s'", path);
@@ -211,8 +231,9 @@ static bool path_is_okay(const char *path)
break;
}
}
-
closedir(dir);
+#endif
+
return retval;
}