2007-07-22 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / metadata / appdomain.c
index a74b266604a2bc2574c6207f178b565d744751a2..020a47cc97be23da621f02b5ea9e8539d36e3558 100644 (file)
@@ -12,7 +12,9 @@
 #include <config.h>
 #include <glib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <mono/utils/mono-logger.h>
 #include <mono/utils/mono-path.h>
 #include <mono/utils/mono-stdlib.h>
+#ifdef PLATFORM_WIN32
+#include <direct.h>
+#endif
 
-#define MONO_CORLIB_VERSION 54
+#define MONO_CORLIB_VERSION 58
 
 CRITICAL_SECTION mono_delegate_section;
 
@@ -630,9 +635,10 @@ add_assemblies_to_domain (MonoDomain *domain, MonoAssembly *ass, GHashTable *ht)
 
        if (ass->image->references) {
                for (i = 0; ass->image->references [i] != NULL; i++) {
-                       if (!g_hash_table_lookup (ht, ass->image->references [i])) {
-                               add_assemblies_to_domain (domain, ass->image->references [i], ht);
-                       }
+                       if (ass->image->references [i] != REFERENCE_MISSING)
+                               if (!g_hash_table_lookup (ht, ass->image->references [i])) {
+                                       add_assemblies_to_domain (domain, ass->image->references [i], ht);
+                               }
                }
        }
        if (destroy_ht)
@@ -844,15 +850,16 @@ static char *
 get_shadow_assembly_location (const char *filename)
 {
        gint32 hash = 0, hash2 = 0;
+       guint32 ticks = GetTickCount ();
        char name_hash [9];
-       char path_hash [19];
+       char path_hash [30];
        char *bname = g_path_get_basename (filename);
        MonoDomain *domain = mono_domain_get ();
        
        hash = get_cstring_hash (bname);
        hash2 = get_cstring_hash (g_path_get_dirname (filename));
-       snprintf (name_hash, sizeof (name_hash), "%08x", hash);
-       snprintf (path_hash, sizeof (path_hash), "%08x_%08x", hash ^ hash2, hash2);
+       g_snprintf (name_hash, sizeof (name_hash), "%08x", hash);
+       g_snprintf (path_hash, sizeof (path_hash), "%08x_%08x_%08x", hash ^ hash2, hash2, ticks);
        return g_build_filename (mono_string_to_utf8 (domain->setup->dynamic_base), 
                                 "assembly", 
                                 "shadow", 
@@ -865,6 +872,56 @@ get_shadow_assembly_location (const char *filename)
 static gboolean
 ensure_directory_exists (const char *filename)
 {
+#ifdef PLATFORM_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;
@@ -880,11 +937,7 @@ ensure_directory_exists (const char *filename)
                p = strchr (p, '/');
                if (p)
                        *p = '\0';
-#ifdef PLATFORM_WIN32
-               retval = mkdir (dir);
-#else
                retval = mkdir (dir, 0777);
-#endif
                if (retval != 0 && errno != EEXIST) {
                        g_free (dir);
                        return FALSE;
@@ -896,6 +949,7 @@ ensure_directory_exists (const char *filename)
        
        g_free (dir);
        return TRUE;
+#endif
 }
 
 static char *
@@ -1113,9 +1167,9 @@ ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname, MonoBoolean re
 
 MonoReflectionAssembly *
 ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad, 
-                                                                                       MonoArray *raw_assembly,
-                                                                                       MonoArray *raw_symbol_store, MonoObject *evidence,
-                                                                                       MonoBoolean refonly)
+                                           MonoArray *raw_assembly,
+                                           MonoArray *raw_symbol_store, MonoObject *evidence,
+                                           MonoBoolean refonly)
 {
        MonoAssembly *ass;
        MonoReflectionAssembly *refass = NULL;