summaryrefslogtreecommitdiff
path: root/test/test-utils-glib.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2017-02-14 19:49:46 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2017-02-20 16:48:23 +0000
commit898ae926dfa0346ad49ed652bd3004705dfc069d (patch)
tree60f6a8946ac45c264ddfdca741145cac4f73ac7e /test/test-utils-glib.c
parenteef176eb72c17773610ef2780133ad2a65fd26c2 (diff)
downloaddbus-898ae926dfa0346ad49ed652bd3004705dfc069d.tar.gz
tests: Wrap file-deletion functions to handle EINTR
The GLib functions we're using don't, and it seems to be possible to be interrupted during cleanup for our tests. Windows apparently has and uses ENOENT for _unlink(), so just do the same on Windows there; but EINTR is very much a POSIX thing, so ignore that on Windows. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825 Reviewed-by: Philip Withnall <withnall@endlessm.com> [smcv: add Windows fixes from a later commit, also reviewed by Philip] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Diffstat (limited to 'test/test-utils-glib.c')
-rw-r--r--test/test-utils-glib.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c
index f90244c3..c5059edb 100644
--- a/test/test-utils-glib.c
+++ b/test/test-utils-glib.c
@@ -27,13 +27,13 @@
#include <config.h>
#include "test-utils-glib.h"
+#include <errno.h>
#include <string.h>
#ifdef DBUS_WIN
# include <io.h>
# include <windows.h>
#else
-# include <errno.h>
# include <signal.h>
# include <unistd.h>
# include <sys/types.h>
@@ -481,3 +481,49 @@ test_progress (char symbol)
if (g_test_verbose () && isatty (1))
g_print ("%c", symbol);
}
+
+/*
+ * Delete @path, with a retry loop if the system call is interrupted by
+ * an async signal. If @path does not exist, ignore; otherwise, it is
+ * required to be a non-directory.
+ */
+void
+test_remove_if_exists (const gchar *path)
+{
+ while (g_remove (path) != 0)
+ {
+ int saved_errno = errno;
+
+ if (saved_errno == ENOENT)
+ return;
+
+#ifdef G_OS_UNIX
+ if (saved_errno == EINTR)
+ continue;
+#endif
+
+ g_error ("Unable to remove file \"%s\": %s", path,
+ g_strerror (saved_errno));
+ }
+}
+
+/*
+ * Delete empty directory @path, with a retry loop if the system call is
+ * interrupted by an async signal. @path is required to exist.
+ */
+void
+test_rmdir_must_exist (const gchar *path)
+{
+ while (g_remove (path) != 0)
+ {
+ int saved_errno = errno;
+
+#ifdef G_OS_UNIX
+ if (saved_errno == EINTR)
+ continue;
+#endif
+
+ g_error ("Unable to remove directory \"%s\": %s", path,
+ g_strerror (saved_errno));
+ }
+}