| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
} |