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:
Benjamin Otte 2019-06-09 21:35:15 +00:00
commit ec5854bb9b
2 changed files with 27 additions and 18 deletions

View File

@ -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;
}

View File

@ -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;
}