[runtime] Use MonoError for mono_make_shadow_copy
authorLudovic Henry <ludovic@xamarin.com>
Mon, 18 Jan 2016 19:38:28 +0000 (19:38 +0000)
committerLudovic Henry <ludovic@xamarin.com>
Wed, 20 Jan 2016 12:57:26 +0000 (12:57 +0000)
mono/metadata/appdomain.c
mono/metadata/assembly.c
mono/metadata/domain-internals.h

index 5cc6e7057d13bf633edae686c47336db41520da7..23f9aa06311d2ff41e9c3695758ff725b97a58bf 100644 (file)
@@ -1249,8 +1249,9 @@ mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name)
 }
 
 char *
-mono_make_shadow_copy (const char *filename)
+mono_make_shadow_copy (const char *filename, MonoError *error)
 {
+       mono_error_init (error);
        return (char *) filename;
 }
 #else
@@ -1628,7 +1629,7 @@ or NULL if source file not found.
 FIXME bubble up the error instead of raising it here
 */
 char *
-mono_make_shadow_copy (const char *filename)
+mono_make_shadow_copy (const char *filename, MonoError *oerror)
 {
        MonoError error;
        gchar *sibling_source, *sibling_target;
@@ -1644,6 +1645,8 @@ mono_make_shadow_copy (const char *filename)
        MonoDomain *domain = mono_domain_get ();
        char *shadow_dir;
 
+       mono_error_init (oerror);
+
        set_domain_search_path (domain);
 
        if (!mono_is_shadow_copy_enabled (domain, dir_name)) {
@@ -1656,8 +1659,8 @@ mono_make_shadow_copy (const char *filename)
        if (!mono_error_ok (&error)) {
                mono_error_cleanup (&error);
                g_free (dir_name);
-               exc = mono_get_exception_execution_engine ("Failed to create shadow copy (invalid characters in shadow directory name).");
-               mono_raise_exception (exc);
+               mono_error_set_generic_error (oerror, "System", "ExecutionEngineException", "Failed to create shadow copy (invalid characters in shadow directory name).");
+               return NULL;
        }
 
        if (strstr (dir_name, shadow_dir)) {
@@ -1671,14 +1674,14 @@ mono_make_shadow_copy (const char *filename)
        shadow = get_shadow_assembly_location (filename, &error);
        if (!mono_error_ok (&error)) {
                mono_error_cleanup (&error);
-               exc = mono_get_exception_execution_engine ("Failed to create shadow copy (invalid characters in file name).");
-               mono_raise_exception (exc);
+               mono_error_set_generic_error (oerror, "System", "ExecutionEngineException", "Failed to create shadow copy (invalid characters in file name).");
+               return NULL;
        }
 
        if (ensure_directory_exists (shadow) == FALSE) {
                g_free (shadow);
-               exc = mono_get_exception_execution_engine ("Failed to create shadow copy (ensure directory exists).");
-               mono_raise_exception (exc);
+               mono_error_set_generic_error (oerror, "System", "ExecutionEngineException", "Failed to create shadow copy (ensure directory exists).");
+               return NULL;
        }       
 
        if (!private_file_needs_copying (filename, &src_sbuf, shadow))
@@ -1714,8 +1717,8 @@ mono_make_shadow_copy (const char *filename)
                if (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND)
                        return NULL; /* file not found, shadow copy failed */
 
-               exc = mono_get_exception_execution_engine ("Failed to create shadow copy (CopyFile).");
-               mono_raise_exception (exc);
+               mono_error_set_generic_error (oerror, "System", "ExecutionEngineException", "Failed to create shadow copy (CopyFile).");
+               return NULL;
        }
 
        /* attempt to copy .mdb, .config if they exist */
@@ -1733,15 +1736,15 @@ mono_make_shadow_copy (const char *filename)
        
        if (copy_result == FALSE)  {
                g_free (shadow);
-               exc = mono_get_exception_execution_engine ("Failed to create shadow copy of sibling data (CopyFile).");
-               mono_raise_exception (exc);
+               mono_error_set_generic_error (oerror, "System", "ExecutionEngineException", "Failed to create shadow copy of sibling data (CopyFile).");
+               return NULL;
        }
 
        /* Create a .ini file containing the original assembly location */
        if (!shadow_copy_create_ini (shadow, filename)) {
                g_free (shadow);
-               exc = mono_get_exception_execution_engine ("Failed to create shadow copy .ini file.");
-               mono_raise_exception (exc);
+               mono_error_set_generic_error (oerror, "System", "ExecutionEngineException", "Failed to create shadow copy .ini file.");
+               return NULL;
        }
 
        utbuf.actime = src_sbuf.st_atime;
index a3916463b691522ce18b0f11b87e17c1d5195102..f381d464b98988397e28d31466b705fd7f6d4e01 100644 (file)
@@ -1577,8 +1577,11 @@ mono_assembly_open_full (const char *filename, MonoImageOpenStatus *status, gboo
                        "Assembly Loader probing location: '%s'.", fname);
 
        new_fname = NULL;
-       if (!mono_assembly_is_in_gac (fname))
-               new_fname = mono_make_shadow_copy (fname);
+       if (!mono_assembly_is_in_gac (fname)) {
+               MonoError error;
+               new_fname = mono_make_shadow_copy (fname, &error);
+               mono_error_raise_exception (&error); /* FIXME don't raise here */
+       }
        if (new_fname && new_fname != fname) {
                g_free (fname);
                fname = new_fname;
index bcf4495e502eee7ce76740ccd20f0178a3c40c0f..09127101d0b8da21371697881ad8f96484de87a3 100644 (file)
@@ -493,7 +493,7 @@ void
 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx);
 
 char *
-mono_make_shadow_copy (const char *filename);
+mono_make_shadow_copy (const char *filename, MonoError *error);
 
 gboolean
 mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name);