Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcos Henrich <marcos.henrich@xamarin.com>2016-05-31 19:28:28 +0300
committerMarcos Henrich <marcos.henrich@xamarin.com>2016-07-09 00:40:38 +0300
commit3bebb7696e67268e9a78bca9be1f3311846abafc (patch)
tree567896616d58c148a0a1d6b21ca0756de479ad42
parent15ddd55f0425da698489dd4ee67d064000a2ff19 (diff)
Moved ensure_directory_exists to eglib.
Moved ensure_directory_exists in apdomain.c to g_ensure_directory_exists in eglib/src/gpath.c so it can be reused.
-rw-r--r--eglib/src/glib.h2
-rw-r--r--eglib/src/gpath.c93
-rw-r--r--mono/metadata/appdomain.c93
3 files changed, 96 insertions, 92 deletions
diff --git a/eglib/src/glib.h b/eglib/src/glib.h
index 72770b2f44f..84ab1ee3f87 100644
--- a/eglib/src/glib.h
+++ b/eglib/src/glib.h
@@ -772,6 +772,8 @@ const gchar *g_get_user_name (void);
gchar *g_get_prgname (void);
void g_set_prgname (const gchar *prgname);
+gboolean g_ensure_directory_exists (const gchar *filename);
+
/*
* Shell
*/
diff --git a/eglib/src/gpath.c b/eglib/src/gpath.c
index 5302f427925..378ef46ad3b 100644
--- a/eglib/src/gpath.c
+++ b/eglib/src/gpath.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <glib.h>
#include <errno.h>
+#include <sys/stat.h>
#ifdef G_OS_WIN32
#include <direct.h>
@@ -294,3 +295,95 @@ g_get_prgname (void)
{
return name;
}
+
+gboolean
+g_ensure_directory_exists (const gchar *filename)
+{
+#ifdef HOST_WIN32
+ gchar *dir_utf8 = g_path_get_dirname (filename);
+ gunichar2 *p;
+ gunichar2 *dir_utf16 = NULL;
+ int retval;
+
+ if (!dir_utf8 || !dir_utf8 [0])
+ return FALSE;
+
+ dir_utf16 = g_utf8_to_utf16 (dir_utf8, strlen (dir_utf8), NULL, NULL, NULL);
+ g_free (dir_utf8);
+
+ if (!dir_utf16)
+ return FALSE;
+
+ p = dir_utf16;
+
+ /* make life easy and only use one directory seperator */
+ while (*p != '\0')
+ {
+ if (*p == '/')
+ *p = '\\';
+ p++;
+ }
+
+ p = dir_utf16;
+
+ /* get past C:\ )*/
+ while (*p++ != '\\')
+ {
+ }
+
+ while (1) {
+ BOOL bRet = FALSE;
+ p = wcschr (p, '\\');
+ if (p)
+ *p = '\0';
+ retval = _wmkdir (dir_utf16);
+ if (retval != 0 && errno != EEXIST) {
+ g_free (dir_utf16);
+ return FALSE;
+ }
+ if (!p)
+ break;
+ *p++ = '\\';
+ }
+
+ g_free (dir_utf16);
+ return TRUE;
+#else
+ char *p;
+ gchar *dir = g_path_get_dirname (filename);
+ int retval;
+ struct stat sbuf;
+
+ if (!dir || !dir [0]) {
+ g_free (dir);
+ return FALSE;
+ }
+
+ if (stat (dir, &sbuf) == 0 && S_ISDIR (sbuf.st_mode)) {
+ g_free (dir);
+ return TRUE;
+ }
+
+ p = dir;
+ while (*p == '/')
+ p++;
+
+ while (1) {
+ p = strchr (p, '/');
+ if (p)
+ *p = '\0';
+ retval = mkdir (dir, 0777);
+ if (retval != 0 && errno != EEXIST) {
+ g_free (dir);
+ return FALSE;
+ }
+ if (!p)
+ break;
+ *p++ = '/';
+ }
+
+ g_free (dir);
+ return TRUE;
+#endif
+}
+
diff --git a/mono/metadata/appdomain.c b/mono/metadata/appdomain.c
index d0d80a5e9de..d20901ed78c 100644
--- a/mono/metadata/appdomain.c
+++ b/mono/metadata/appdomain.c
@@ -1514,97 +1514,6 @@ get_shadow_assembly_location (const char *filename, MonoError *error)
}
static gboolean
-ensure_directory_exists (const char *filename)
-{
-#ifdef HOST_WIN32
- gchar *dir_utf8 = g_path_get_dirname (filename);
- gunichar2 *p;
- gunichar2 *dir_utf16 = NULL;
- int retval;
-
- if (!dir_utf8 || !dir_utf8 [0])
- return FALSE;
-
- dir_utf16 = g_utf8_to_utf16 (dir_utf8, strlen (dir_utf8), NULL, NULL, NULL);
- g_free (dir_utf8);
-
- if (!dir_utf16)
- return FALSE;
-
- p = dir_utf16;
-
- /* make life easy and only use one directory seperator */
- while (*p != '\0')
- {
- if (*p == '/')
- *p = '\\';
- p++;
- }
-
- p = dir_utf16;
-
- /* get past C:\ )*/
- while (*p++ != '\\')
- {
- }
-
- while (1) {
- BOOL bRet = FALSE;
- p = wcschr (p, '\\');
- if (p)
- *p = '\0';
- retval = _wmkdir (dir_utf16);
- if (retval != 0 && errno != EEXIST) {
- g_free (dir_utf16);
- return FALSE;
- }
- if (!p)
- break;
- *p++ = '\\';
- }
-
- g_free (dir_utf16);
- return TRUE;
-#else
- char *p;
- gchar *dir = g_path_get_dirname (filename);
- int retval;
- struct stat sbuf;
-
- if (!dir || !dir [0]) {
- g_free (dir);
- return FALSE;
- }
-
- if (stat (dir, &sbuf) == 0 && S_ISDIR (sbuf.st_mode)) {
- g_free (dir);
- return TRUE;
- }
-
- p = dir;
- while (*p == '/')
- p++;
-
- while (1) {
- p = strchr (p, '/');
- if (p)
- *p = '\0';
- retval = mkdir (dir, 0777);
- if (retval != 0 && errno != EEXIST) {
- g_free (dir);
- return FALSE;
- }
- if (!p)
- break;
- *p++ = '/';
- }
-
- g_free (dir);
- return TRUE;
-#endif
-}
-
-static gboolean
private_file_needs_copying (const char *src, struct stat *sbuf_src, char *dest)
{
struct stat sbuf_dest;
@@ -1802,7 +1711,7 @@ mono_make_shadow_copy (const char *filename, MonoError *oerror)
return NULL;
}
- if (ensure_directory_exists (shadow) == FALSE) {
+ if (g_ensure_directory_exists (shadow) == FALSE) {
g_free (shadow);
mono_error_set_execution_engine (oerror, "Failed to create shadow copy (ensure directory exists).");
return NULL;