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 <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
ff402d21ab
commit
4b192c0773
@ -309,7 +309,9 @@ static inline void key_generic_reload(void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = io_reload_data();
|
ret = io_reload_data();
|
||||||
if (ret != IO_RELOAD_CANCEL && ret != IO_RELOAD_NOOP) {
|
if (ret == IO_RELOAD_LOAD ||
|
||||||
|
ret == IO_RELOAD_CTINUE ||
|
||||||
|
ret == IO_RELOAD_MERGE) {
|
||||||
ui_todo_load_items();
|
ui_todo_load_items();
|
||||||
ui_todo_sel_reset();
|
ui_todo_sel_reset();
|
||||||
do_storage(0);
|
do_storage(0);
|
||||||
@ -331,6 +333,8 @@ static inline void key_generic_reload(void)
|
|||||||
case IO_RELOAD_NOOP:
|
case IO_RELOAD_NOOP:
|
||||||
msg = _("Data were already loaded");
|
msg = _("Data were already loaded");
|
||||||
break;
|
break;
|
||||||
|
case IO_RELOAD_ERROR:
|
||||||
|
EXIT(_("Cannot open data file"));
|
||||||
}
|
}
|
||||||
status_mesg(msg, "");
|
status_mesg(msg, "");
|
||||||
}
|
}
|
||||||
|
@ -673,7 +673,8 @@ enum {
|
|||||||
IO_RELOAD_CTINUE,
|
IO_RELOAD_CTINUE,
|
||||||
IO_RELOAD_MERGE,
|
IO_RELOAD_MERGE,
|
||||||
IO_RELOAD_CANCEL,
|
IO_RELOAD_CANCEL,
|
||||||
IO_RELOAD_NOOP
|
IO_RELOAD_NOOP,
|
||||||
|
IO_RELOAD_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Week days. */
|
/* Week days. */
|
||||||
|
24
src/io.c
24
src/io.c
@ -444,12 +444,15 @@ static int resolve_save_conflict(void)
|
|||||||
return ret;
|
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 NONEW 0
|
||||||
#define APTS 1
|
#define APTS (1 << 0)
|
||||||
#define TODO 2
|
#define TODO (1 << 1)
|
||||||
#define APTS_TODO 3
|
#define APTS_TODO APTS | TODO
|
||||||
#define NOKNOW 4
|
#define NOKNOW -1
|
||||||
static int new_data()
|
static int new_data()
|
||||||
{
|
{
|
||||||
char sha1_new[SHA1_DIGESTLEN * 2 + 1];
|
char sha1_new[SHA1_DIGESTLEN * 2 + 1];
|
||||||
@ -813,8 +816,8 @@ void io_load_todo(struct item_filter *filter)
|
|||||||
/*
|
/*
|
||||||
* Load appointments and todo items.
|
* Load appointments and todo items.
|
||||||
* Unless told otherwise, the function will only load a file that has changed
|
* Unless told otherwise, the function will only load a file that has changed
|
||||||
* since last saved or loaded, see new_data() return codes.
|
* since last saved or loaded. The new_data() return code is passed on when
|
||||||
* Return codes are for use in io_reload_data() only.
|
* 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)
|
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
|
else
|
||||||
force = new_data();
|
force = new_data();
|
||||||
|
|
||||||
|
if (force == NOKNOW)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
if (force & APTS) {
|
if (force & APTS) {
|
||||||
apoint_llist_free();
|
apoint_llist_free();
|
||||||
event_llist_free();
|
event_llist_free();
|
||||||
@ -842,7 +848,7 @@ int io_load_data(struct item_filter *filter, int force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
io_unset_modified();
|
io_unset_modified();
|
||||||
|
exit:
|
||||||
run_hook("post-load");
|
run_hook("post-load");
|
||||||
return force;
|
return force;
|
||||||
}
|
}
|
||||||
@ -889,6 +895,8 @@ int io_reload_data(void)
|
|||||||
load = io_load_data(NULL, load);
|
load = io_load_data(NULL, load);
|
||||||
if (load == NONEW)
|
if (load == NONEW)
|
||||||
ret = IO_RELOAD_NOOP;
|
ret = IO_RELOAD_NOOP;
|
||||||
|
else if (load == NOKNOW)
|
||||||
|
ret = IO_RELOAD_ERROR;
|
||||||
cleanup:
|
cleanup:
|
||||||
io_mutex_unlock();
|
io_mutex_unlock();
|
||||||
mem_free(msg_um_asktype);
|
mem_free(msg_um_asktype);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user