Distinguish between interactive and periodic save

A new argument to io_save_cal() makes it possible for the periodic save thread
to avoid 1) user interaction and 2) overwriting new data.

At the moment the thread has no way to report on the result of the save.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2018-08-30 16:20:15 +02:00 committed by Lukas Fleischer
parent 39ab4665e6
commit 657f007cd2
3 changed files with 17 additions and 9 deletions

View File

@ -274,7 +274,7 @@ static inline void key_generic_save(void)
char *msg = NULL; char *msg = NULL;
int ret; int ret;
ret = io_save_cal(); ret = io_save_cal(interactive);
if (ret == IO_SAVE_RELOAD) { if (ret == IO_SAVE_RELOAD) {
ui_todo_load_items(); ui_todo_load_items();
@ -505,7 +505,7 @@ static inline void key_generic_scroll_down(void)
static inline void key_generic_quit(void) static inline void key_generic_quit(void)
{ {
if (conf.auto_save) if (conf.auto_save)
io_save_cal(); io_save_cal(interactive);
if (conf.auto_gc) if (conf.auto_gc)
note_gc(); note_gc();
@ -540,7 +540,7 @@ static inline void key_generic_cmd(void)
if (!strcmp(cmd_name, "write") || !strcmp(cmd_name, "w") || if (!strcmp(cmd_name, "write") || !strcmp(cmd_name, "w") ||
!strcmp(cmd_name, "wq")) { !strcmp(cmd_name, "wq")) {
io_save_cal(); io_save_cal(interactive);
valid = 1; valid = 1;
} }
if (!strcmp(cmd_name, "quit") || !strcmp(cmd_name, "q") || if (!strcmp(cmd_name, "quit") || !strcmp(cmd_name, "q") ||

View File

@ -654,7 +654,11 @@ enum getstr {
#define PARSE_DATETIME_HAS_DATE (1 << 0) #define PARSE_DATETIME_HAS_DATE (1 << 0)
#define PARSE_DATETIME_HAS_TIME (1 << 1) #define PARSE_DATETIME_HAS_TIME (1 << 1)
/* Return codes for the io_save_cal() function. */ /* Save types and return codes for the io_save_cal() function. */
enum save_type {
interactive,
periodic
};
enum { enum {
IO_SAVE_CTINUE, IO_SAVE_CTINUE,
IO_SAVE_RELOAD, IO_SAVE_RELOAD,
@ -862,7 +866,7 @@ unsigned io_save_apts(const char *);
void io_dump_todo(const char *); void io_dump_todo(const char *);
unsigned io_save_todo(const char *); unsigned io_save_todo(const char *);
unsigned io_save_keys(void); unsigned io_save_keys(void);
int io_save_cal(void); int io_save_cal(enum save_type);
void io_load_app(struct item_filter *); void io_load_app(struct item_filter *);
void io_load_todo(struct item_filter *); void io_load_todo(struct item_filter *);
int io_load_data(struct item_filter *, int); int io_load_data(struct item_filter *, int);

View File

@ -490,16 +490,20 @@ cleanup:
* IO_SAVE_NOOP: cancel save operation (nothing has changed) * IO_SAVE_NOOP: cancel save operation (nothing has changed)
* IO_SAVE_ERROR: cannot access data * IO_SAVE_ERROR: cannot access data
*/ */
int io_save_cal(void) int io_save_cal(enum save_type s_t)
{ {
int ret; int ret;
if (read_only) if (read_only)
return IO_SAVE_CANCEL; return IO_SAVE_CANCEL;
if ((ret = new_data()) == NOKNOW) { if ((ret = new_data()) == NOKNOW)
return IO_SAVE_ERROR; return IO_SAVE_ERROR;
} else if (ret) { /* New data */
if (ret) { /* New data */
if (s_t == periodic)
return IO_SAVE_CANCEL;
/* Interactively decide what to do. */
if ((ret = resolve_save_conflict())) if ((ret = resolve_save_conflict()))
return ret; return ret;
} else /* No new data */ } else /* No new data */
@ -1422,7 +1426,7 @@ static void *io_psave_thread(void *arg)
for (;;) { for (;;) {
sleep(delay * MININSEC); sleep(delay * MININSEC);
io_save_cal(); io_save_cal(periodic);
} }
} }