forked from AuroraMiddleware/gtk
Merge branch 'for-master' into 'master'
testsuite: Make creating the output dir not racy Closes #1942 See merge request GNOME/gtk!924
This commit is contained in:
commit
ec5854bb9b
@ -11,6 +11,7 @@ get_output_dir (void)
|
||||
{
|
||||
static const char *output_dir = NULL;
|
||||
GError *error = NULL;
|
||||
GFile *file;
|
||||
|
||||
if (output_dir)
|
||||
return output_dir;
|
||||
@ -26,21 +27,26 @@ get_output_dir (void)
|
||||
output_dir = g_get_tmp_dir ();
|
||||
}
|
||||
|
||||
if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
|
||||
/* Just try to create the output directory.
|
||||
* If it already exists, that's exactly what we wanted to check,
|
||||
* so we can happily skip that error.
|
||||
*/
|
||||
file = g_file_new_for_path (output_dir);
|
||||
if (!g_file_make_directory_with_parents (file, NULL, &error))
|
||||
{
|
||||
GFile *file;
|
||||
g_object_unref (file);
|
||||
|
||||
file = g_file_new_for_path (output_dir);
|
||||
if (!g_file_make_directory_with_parents (file, NULL, &error))
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_error ("Failed to create output dir: %s", error->message);
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
|
||||
return output_dir;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,21 @@ get_output_dir (GError **error)
|
||||
|
||||
if (arg_output_dir)
|
||||
{
|
||||
GFile *file = g_file_new_for_commandline_arg (arg_output_dir);
|
||||
GError *err = NULL;
|
||||
GFile *file;
|
||||
|
||||
file = g_file_new_for_commandline_arg (arg_output_dir);
|
||||
if (!g_file_make_directory_with_parents (file, NULL, &err))
|
||||
{
|
||||
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_EXISTS))
|
||||
{
|
||||
g_propagate_error (error, err);
|
||||
g_object_unref (file);
|
||||
return NULL;
|
||||
}
|
||||
g_clear_error (&err);
|
||||
}
|
||||
|
||||
output_dir = g_file_get_path (file);
|
||||
g_object_unref (file);
|
||||
}
|
||||
@ -104,17 +118,6 @@ get_output_dir (GError **error)
|
||||
output_dir = g_get_tmp_dir ();
|
||||
}
|
||||
|
||||
if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
GFile *file;
|
||||
|
||||
file = g_file_new_for_path (output_dir);
|
||||
if (!g_file_make_directory_with_parents (file, NULL, error))
|
||||
return NULL;
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
return output_dir;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user