Moved ensure_directory_exists to eglib.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Tue, 31 May 2016 16:28:28 +0000 (17:28 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Fri, 8 Jul 2016 21:40:38 +0000 (22:40 +0100)
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
eglib/src/gpath.c
mono/metadata/appdomain.c

index 72770b2f44fab3fae7b0a5312b83d802df98524e..84ab1ee3f87c0d015302a0993bae88926e9b97a0 100644 (file)
@@ -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
  */
index 5302f427925453496b43d0b4babb88daacbd9bf1..378ef46ad3b6f2d68d83bf62a042c8a608a85170 100644 (file)
@@ -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
+}
+
index d0d80a5e9de50412ab0b05cbe5a7f612d943fd14..d20901ed78cefba9a8977b5b2b0c7cd5a4339c7c 100644 (file)
@@ -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;