tests: fix a small lie
[dconf.git] / tests / tmpdir.c
blobb8c87452347e799acebd431590ca2d16ccfd1d0e
1 #include "tmpdir.h"
3 #include <glib/gstdio.h>
4 #include "../common/dconf-paths.h"
5 #include <string.h>
7 gchar *
8 dconf_test_create_tmpdir (void)
10 GError *error = NULL;
11 gchar *temp;
13 temp = g_dir_make_tmp ("dconf-testcase.XXXXXX", &error);
14 g_assert_no_error (error);
15 g_assert (temp != NULL);
17 return temp;
20 static void
21 rm_rf (const gchar *file)
23 GDir *dir;
25 dir = g_dir_open (file, 0, NULL);
26 if (dir)
28 const gchar *basename;
30 while ((basename = g_dir_read_name (dir)))
32 gchar *fullname;
34 fullname = g_build_filename (file, basename, NULL);
35 rm_rf (fullname);
36 g_free (fullname);
39 g_dir_close (dir);
40 g_rmdir (file);
43 else
44 /* excess paranoia -- only unlink if we're really really sure */
45 if (strstr (file, "/dconf-testcase") && !strstr (file, ".."))
46 g_unlink (file);
49 void
50 dconf_test_remove_tmpdir (const gchar *tmpdir)
52 rm_rf (tmpdir);