Debian Codegraph @

benchmark/lib/bench-utils.c

raw symbols SCIP
1 /*
2 Copyright (C) 2008 Kouhei Sutou <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <errno.h>
20 #include <glib/gstdio.h>
21
22 #include "bench-utils.h"
23
24 gboolean
25 bench_utils_remove_path(const gchar *path, GError **error)
26 {
27 if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
28 g_set_error(error, G_FILE_ERROR, G_FILE_ERROR_NOENT,
29 "path doesn't exist: %s", path);
30 return FALSE;
31 }
32
33 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
34 if (g_rmdir(path) == -1) {
35 g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno),
36 "can't remove directory: %s", path);
37 return FALSE;
38 }
39 } else {
40 if (g_unlink(path) == -1) {
41 g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno),
42 "can't remove path: %s", path);
43 return FALSE;
44 }
45 }
46
47 return TRUE;
48 }
49
50 gboolean
51 bench_utils_remove_path_recursive(const gchar *path, GError **error)
52 {
53 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
54 GDir *dir;
55 const gchar *name;
56
57 dir = g_dir_open(path, 0, error);
58 if (!dir)
59 return FALSE;
60
61 while ((name = g_dir_read_name(dir))) {
62 const gchar *full_path;
63
64 full_path = g_build_filename(path, name, NULL);
65 if (!bench_utils_remove_path_recursive(full_path, error))
66 return FALSE;
67 }
68
69 g_dir_close(dir);
70
71 return bench_utils_remove_path(path, error);
72 } else {
73 return bench_utils_remove_path(path, error);
74 }
75
76 return TRUE;
77 }
78
79 void
80 bench_utils_remove_path_recursive_force(const gchar *path)
81 {
82 bench_utils_remove_path_recursive(path, NULL);
83 }