From 4b192c07733eac9be3404304cae3cf0c17374cec Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Wed, 5 Sep 2018 08:46:16 +0200 Subject: Error return code for io_reload_data() The return code from new_data() and io_load_data() is explicitly defined as a bit mask. A file access error is recognised and reported back to the user. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/io.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index 72b2bba..9f20a18 100644 --- a/src/io.c +++ b/src/io.c @@ -444,12 +444,15 @@ static int resolve_save_conflict(void) return ret; } -/* Return codes for new_data(). */ +/* + * Return codes for new_data() and io_load_data(). + * Note that they are file internal. + */ #define NONEW 0 -#define APTS 1 -#define TODO 2 -#define APTS_TODO 3 -#define NOKNOW 4 +#define APTS (1 << 0) +#define TODO (1 << 1) +#define APTS_TODO APTS | TODO +#define NOKNOW -1 static int new_data() { char sha1_new[SHA1_DIGESTLEN * 2 + 1]; @@ -813,8 +816,8 @@ void io_load_todo(struct item_filter *filter) /* * Load appointments and todo items. * Unless told otherwise, the function will only load a file that has changed - * since last saved or loaded, see new_data() return codes. - * Return codes are for use in io_reload_data() only. + * since last saved or loaded. The new_data() return code is passed on when + * force is false. When force is true (FORCE), the return code is of no use. */ int io_load_data(struct item_filter *filter, int force) { @@ -824,6 +827,9 @@ int io_load_data(struct item_filter *filter, int force) else force = new_data(); + if (force == NOKNOW) + goto exit; + if (force & APTS) { apoint_llist_free(); event_llist_free(); @@ -842,7 +848,7 @@ int io_load_data(struct item_filter *filter, int force) } io_unset_modified(); - + exit: run_hook("post-load"); return force; } @@ -889,6 +895,8 @@ int io_reload_data(void) load = io_load_data(NULL, load); if (load == NONEW) ret = IO_RELOAD_NOOP; + else if (load == NOKNOW) + ret = IO_RELOAD_ERROR; cleanup: io_mutex_unlock(); mem_free(msg_um_asktype); -- cgit v1.2.3-54-g00ecf