[runtime] Use IOAMP-aware method of looking for domain configuration file
authorMarek Habersack <grendel@twistedcode.net>
Fri, 28 Jan 2011 23:29:44 +0000 (00:29 +0100)
committerMarek Habersack <grendel@twistedcode.net>
Mon, 31 Jan 2011 08:29:47 +0000 (09:29 +0100)
mono/metadata/appdomain.c
mono/metadata/assembly.c
mono/metadata/icall.c
mono/utils/mono-io-portability.c

index ab1fc103a1a9e67fa4d47ec5fc20c2c001468485..1b53294c8c1c4171fc121cdcd93acfc2b7a5993c 100644 (file)
@@ -816,7 +816,7 @@ void
 mono_set_private_bin_path_from_config (MonoDomain *domain)
 {
        MonoError error;
-       gchar *config_file, *text;
+       gchar *config_file_name = NULL, *text = NULL, *config_file_path = NULL;
        gsize len;
        GMarkupParseContext *context;
        RuntimeConfig runtime_config;
@@ -825,21 +825,23 @@ mono_set_private_bin_path_from_config (MonoDomain *domain)
        if (!domain || !domain->setup || !domain->setup->configuration_file)
                return;
 
-       config_file = mono_string_to_utf8_checked (domain->setup->configuration_file, &error); 
+       config_file_name = mono_string_to_utf8_checked (domain->setup->configuration_file, &error);
        if (!mono_error_ok (&error)) {
                mono_error_cleanup (&error);
-               return;
+               goto free_and_out;
        }
 
-       if (!g_file_get_contents (config_file, &text, &len, NULL)) {
-               g_free (config_file);
-               return;
-       }
+       config_file_path = mono_portability_find_file (config_file_name, TRUE);
+       if (!config_file_path)
+               config_file_path = config_file_name;
+
+       if (!g_file_get_contents (config_file_path, &text, &len, NULL))
+               goto free_and_out;
 
        runtime_config.runtime_count = 0;
        runtime_config.assemblybinding_count = 0;
        runtime_config.domain = domain;
-       runtime_config.filename = config_file;
+       runtime_config.filename = config_file_path;
        
        offset = 0;
        if (len > 3 && text [0] == '\xef' && text [1] == (gchar) '\xbb' && text [2] == '\xbf')
@@ -849,8 +851,12 @@ mono_set_private_bin_path_from_config (MonoDomain *domain)
        if (g_markup_parse_context_parse (context, text + offset, len - offset, NULL))
                g_markup_parse_context_end_parse (context, NULL);
        g_markup_parse_context_free (context);
+
+  free_and_out:
        g_free (text);
-       g_free (config_file);
+       if (config_file_name != config_file_path)
+               g_free (config_file_name);
+       g_free (config_file_path);
 }
 
 MonoAppDomain *
index cdd9ca8d254e0fcbd404a61d3ff12e2752b92a48..3eab38878e3dd28e0ba85f04c3bd398491cbf4ed 100644 (file)
@@ -32,6 +32,7 @@
 #include <mono/utils/mono-path.h>
 #include <mono/metadata/reflection.h>
 #include <mono/metadata/coree.h>
+#include <mono/utils/mono-io-portability.h>
 
 #ifndef HOST_WIN32
 #include <sys/types.h>
@@ -2457,11 +2458,17 @@ mono_assembly_apply_binding (MonoAssemblyName *aname, MonoAssemblyName *dest_nam
        if (domain && domain->setup && domain->setup->configuration_file) {
                mono_domain_lock (domain);
                if (!domain->assembly_bindings_parsed) {
-                       gchar *domain_config_file = mono_string_to_utf8 (domain->setup->configuration_file);
+                       gchar *domain_config_file_name = mono_string_to_utf8 (domain->setup->configuration_file);
+                       gchar *domain_config_file_path = mono_portability_find_file (domain_config_file_name, TRUE);
 
-                       mono_config_parse_assembly_bindings (domain_config_file, aname->major, aname->minor, domain, assembly_binding_info_parsed);
+                       if (!domain_config_file_path)
+                               domain_config_file_path = domain_config_file_name;
+                       
+                       mono_config_parse_assembly_bindings (domain_config_file_path, aname->major, aname->minor, domain, assembly_binding_info_parsed);
                        domain->assembly_bindings_parsed = TRUE;
-                       g_free (domain_config_file);
+                       if (domain_config_file_name != domain_config_file_path)
+                               g_free (domain_config_file_name);
+                       g_free (domain_config_file_path);
                }
                mono_domain_unlock (domain);
 
index 719e19ffbf3915122636657a8b141560bc7fa2d7..aed1b2cd274ba7b84943a998731ae9cc5aa5bf70 100644 (file)
@@ -77,6 +77,7 @@
 #include <mono/utils/mono-string.h>
 #include <mono/utils/mono-error-internals.h>
 #include <mono/utils/mono-mmap.h>
+#include <mono/utils/mono-io-portability.h>
 
 #if defined (HOST_WIN32)
 #include <windows.h>
@@ -6920,7 +6921,7 @@ get_bundled_app_config (void)
        const gchar *app_config;
        MonoDomain *domain;
        MonoString *file;
-       gchar *config_file;
+       gchar *config_file_name, *config_file_path;
        gsize len;
        gchar *module;
 
@@ -6932,15 +6933,20 @@ get_bundled_app_config (void)
                return NULL;
 
        // Retrieve config file and remove the extension
-       config_file = mono_string_to_utf8 (file);
-       len = strlen (config_file) - strlen (".config");
+       config_file_name = mono_string_to_utf8 (file);
+       config_file_path = mono_portability_find_file (config_file_name, TRUE);
+       if (!config_file_path)
+               config_file_path = config_file_name;
+       len = strlen (config_file_path) - strlen (".config");
        module = g_malloc0 (len + 1);
-       memcpy (module, config_file, len);
+       memcpy (module, config_file_path, len);
        // Get the config file from the module name
        app_config = mono_config_string_for_assembly_file (module);
        // Clean-up
        g_free (module);
-       g_free (config_file);
+       if (config_file_name != config_file_path)
+               g_free (config_file_name);
+       g_free (config_file_path);
 
        if (!app_config)
                return NULL;
index 5a48418e4f32ddac7375029f5e3a46faa8c96e3e..20cc96ba46ca35644f8abb920eb15bb7f6db3c85 100644 (file)
@@ -25,7 +25,6 @@ mono_portability_helpers_init (void)
 gchar *
 mono_portability_find_file (const gchar *pathname, gboolean last_exists)
 {
-       g_assert_not_reached();
        return NULL;
 }
 
@@ -147,7 +146,11 @@ static inline void do_mono_profiler_iomap (GString **report, const char *pathnam
 gchar *mono_portability_find_file (const gchar *pathname, gboolean last_exists)
 {
        GString *report = NULL;
-       gchar *ret = mono_portability_find_file_internal (&report, pathname, last_exists);
+       gchar *ret;
+       
+       if (!pathname || !pathname [0])
+               return NULL;
+       ret = mono_portability_find_file_internal (&report, pathname, last_exists);
 
        if (report)
                g_string_free (report, TRUE);