From 319a6107f5547477903c685314cee991269ac342 Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Mon, 30 Dec 2019 00:00:51 -0500 Subject: [PATCH] refactor(file): use glib helpers for file checking --- src/config.c | 2 +- src/file.c | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/config.c b/src/config.c index 04aa116..1a8fe78 100644 --- a/src/config.c +++ b/src/config.c @@ -18,7 +18,7 @@ bool config_get_storage_path(struct swappy_state *state) { if (wordexp(storage_paths[i], &p, 0) == 0) { char *path = g_strdup(p.we_wordv[0]); wordfree(&p); - if (folder_exists(path)) { + if (path && folder_exists(path)) { g_info("storage path is: %s", path); state->storage_path = path; return true; diff --git a/src/file.c b/src/file.c index 058b064..4b8dc57 100644 --- a/src/file.c +++ b/src/file.c @@ -12,19 +12,11 @@ #define BLOCK_SIZE 1024 bool folder_exists(const char *path) { - struct stat sb; - - stat(path, &sb); - - return (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)); + return g_file_test(path, G_FILE_TEST_IS_DIR); } bool file_exists(const char *path) { - struct stat sb; - - stat(path, &sb); - - return (stat(path, &sb) == 0 && S_ISREG(sb.st_mode)); + return g_file_test(path, G_FILE_TEST_EXISTS); } char *file_dump_stdin_into_a_temp_file() {