[gtk/for-master] testsuite: Make creating the output dir not racy
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/for-master] testsuite: Make creating the output dir not racy
- Date: Sun, 9 Jun 2019 21:17:57 +0000 (UTC)
commit 062244ab714ad000d7dd41d512e9fbccc64a712c
Author: Benjamin Otte <otte redhat com>
Date: Sun Jun 9 21:49:44 2019 +0200
testsuite: Make creating the output dir not racy
Fixes #1942
testsuite/gsk/compare-render.c | 18 ++++++++++++------
testsuite/reftests/gtk-reftest.c | 27 +++++++++++++++------------
2 files changed, 27 insertions(+), 18 deletions(-)
---
diff --git a/testsuite/gsk/compare-render.c b/testsuite/gsk/compare-render.c
index d15416c88a..a0e68a37cd 100644
--- a/testsuite/gsk/compare-render.c
+++ b/testsuite/gsk/compare-render.c
@@ -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;
}
diff --git a/testsuite/reftests/gtk-reftest.c b/testsuite/reftests/gtk-reftest.c
index b0fb5741f6..f54244db3e 100644
--- a/testsuite/reftests/gtk-reftest.c
+++ b/testsuite/reftests/gtk-reftest.c
@@ -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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]