From 3bebb7696e67268e9a78bca9be1f3311846abafc Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Tue, 31 May 2016 17:28:28 +0100 Subject: [PATCH] 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. --- eglib/src/glib.h | 2 + eglib/src/gpath.c | 93 +++++++++++++++++++++++++++++++++++++++ mono/metadata/appdomain.c | 93 +-------------------------------------- 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 #include #include +#include #ifdef G_OS_WIN32 #include @@ -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 @@ -1513,97 +1513,6 @@ get_shadow_assembly_location (const char *filename, MonoError *error) return location; } -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) { @@ -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; -- 2.25.1