From aad90782ba81c560db6501d687e2d3724cc3aca5 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 23 Mar 2016 09:39:37 -0400 Subject: [PATCH] core/collection: Clean up error handling code I was assuming that my disk returns -EIO when it enters its failed state, but it really seems to be return -ENOENT. Let's have this code check for any error, rather than one specific one. Signed-off-by: Anna Schumaker --- core/collection.c | 33 ++++++++++----------------------- include/core/collection.h | 2 +- tests/core/collection.c | 10 +++++----- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/core/collection.c b/core/collection.c index 758a114e..9d6d7021 100644 --- a/core/collection.c +++ b/core/collection.c @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -23,28 +22,18 @@ static void __scan_dir(void *); #ifdef CONFIG_TESTING -bool test_collection_eio = false; -static inline int __g_access(const gchar *path, int mode) +bool test_collection_error = false; +static inline int __g_access(const gchar *path) { - if (test_collection_eio) { - errno = EIO; + if (test_collection_error) return -1; - } return g_access(path, F_OK); } #else -#define __g_access g_access +#define __g_access(path) g_access(path, F_OK) #endif /* CONFIG_TESTING */ -static inline int __check_access(const gchar *path) -{ - int ret = __g_access(path, F_OK); - if (ret == -1) - return -errno; - return ret; -} - static void __scan_dir_later(struct library *library, const gchar *dir) { struct scan_data *data = g_malloc(sizeof(struct scan_data)); @@ -111,14 +100,12 @@ static void __validate_library(void *data) continue; path = track_path(track); - access = __check_access(path); + access = __g_access(path); g_free(path); - if (access == -EIO) { - if (collection_check_library(library) == -EIO) - return; - } if (access < 0) { + if (collection_check_library(library) < 0) + return; queue_remove_all(&c_queue, track); track_remove(track); } @@ -255,7 +242,7 @@ void collection_set_enabled(struct library *library, bool enabled) if (!library || (library->li_enabled == enabled)) return; - if (enabled && (collection_check_library(library) == -EIO)) + if (enabled && (collection_check_library(library) < 0)) return; library_set_enabled(library, enabled); @@ -278,8 +265,8 @@ void collection_set_enabled(struct library *library, bool enabled) int collection_check_library(struct library *library) { - int ret = __check_access(library->li_path); - if (ret == -EIO) { + int ret = __g_access(library->li_path); + if (ret < 0) { g_warning("Can't access library at %s/\n", library->li_path); collection_set_enabled(library, false); } diff --git a/include/core/collection.h b/include/core/collection.h index f42af95c..8834a7d2 100644 --- a/include/core/collection.h +++ b/include/core/collection.h @@ -56,7 +56,7 @@ struct queue *collection_get_queue(); #ifdef CONFIG_TESTING -extern bool test_collection_eio; +extern bool test_collection_error; #endif /* CONFIG_TESTING */ #endif /* OCARINA_CORE_COLLECTION_H */ diff --git a/tests/core/collection.c b/tests/core/collection.c index c5d8ed57..1d4a5fec 100644 --- a/tests/core/collection.c +++ b/tests/core/collection.c @@ -236,8 +236,8 @@ static void test_eio() test_equal(lib->li_enabled, (bool)true); test_equal(queue_size(q), 48); - test_collection_eio = true; - test_equal(collection_check_library(lib), -EIO); + test_collection_error = true; + test_equal(collection_check_library(lib), -1); test_equal(lib->li_enabled, (bool)false); test_equal(queue_size(q), 0); @@ -245,18 +245,18 @@ static void test_eio() test_equal(lib->li_enabled, (bool)false); test_equal(queue_size(q), 0); - test_collection_eio = false; + test_collection_error = false; collection_set_enabled(lib, true); test_equal(lib->li_enabled, (bool)true); test_equal(queue_size(q), 48); - test_collection_eio = true; + test_collection_error = true; collection_update_all(); test_equal(idle_run_task(), (bool)true); test_equal(lib->li_enabled, (bool)false); test_equal(queue_size(q), 0); - test_collection_eio = false; + test_collection_error = false; collection_set_enabled(lib, true); test_equal(lib->li_enabled, (bool)true); test_equal(queue_size(q), 48);