Return failure if import skips any item

Other items may have been imported succesfully.

Adresses Github issue #323, last part.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2020-11-03 19:28:19 +01:00 committed by Lukas Fleischer
parent d126696999
commit 97df01b534
3 changed files with 13 additions and 8 deletions

View File

@ -428,7 +428,7 @@ int parse_args(int argc, char **argv)
const char *cfile = NULL, *confdir = NULL; const char *cfile = NULL, *confdir = NULL;
char *ifile = NULL; char *ifile = NULL;
int non_interactive = 1; int ret, non_interactive = 1;
int ch, cpid, type; int ch, cpid, type;
regex_t reg; regex_t reg;
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -963,10 +963,12 @@ int parse_args(int argc, char **argv)
fmt_apt = fmt_rapt = fmt_ev = fmt_rev = NULL; fmt_apt = fmt_rapt = fmt_ev = fmt_rev = NULL;
fmt_todo = NULL; fmt_todo = NULL;
} }
io_import_data(IO_IMPORT_ICAL, ifile, fmt_ev, fmt_rev, fmt_apt, ret = io_import_data(IO_IMPORT_ICAL, ifile, fmt_ev, fmt_rev,
fmt_rapt, fmt_todo); fmt_apt, fmt_rapt, fmt_todo);
io_save_apts(path_apts); io_save_apts(path_apts);
io_save_todo(path_todo); io_save_todo(path_todo);
if (!ret)
exit_calcurse(EXIT_FAILURE);
} else if (export) { } else if (export) {
io_check_file(path_apts); io_check_file(path_apts);
io_check_file(path_todo); io_check_file(path_todo);

View File

@ -924,7 +924,7 @@ unsigned io_file_exists(const char *);
int io_check_file(const char *); int io_check_file(const char *);
int io_check_data_files(void); int io_check_data_files(void);
void io_export_data(enum export_type, int); void io_export_data(enum export_type, int);
void io_import_data(enum import_type, char *, const char *, const char *, int io_import_data(enum import_type, char *, const char *, const char *,
const char *, const char *, const char *); const char *, const char *, const char *);
struct io_file *io_log_init(void); struct io_file *io_log_init(void);
void io_log_print(struct io_file *, int, const char *); void io_log_print(struct io_file *, int, const char *);

View File

@ -1277,7 +1277,7 @@ static FILE *get_import_stream(enum import_type type, char **stream_name)
* A temporary log file is created in /tmp to store the import process report, * A temporary log file is created in /tmp to store the import process report,
* and is cleared at the end. * and is cleared at the end.
*/ */
void io_import_data(enum import_type type, char *stream_name, int io_import_data(enum import_type type, char *stream_name,
const char *fmt_ev, const char *fmt_rev, const char *fmt_ev, const char *fmt_rev,
const char *fmt_apt, const char *fmt_rapt, const char *fmt_apt, const char *fmt_rapt,
const char *fmt_todo) const char *fmt_todo)
@ -1312,7 +1312,7 @@ void io_import_data(enum import_type type, char *stream_name,
} }
if (stream == NULL) if (stream == NULL)
return; return 0;
memset(&stats, 0, sizeof stats); memset(&stats, 0, sizeof stats);
@ -1320,7 +1320,7 @@ void io_import_data(enum import_type type, char *stream_name,
if (log == NULL) { if (log == NULL) {
if (stream != stdin) if (stream != stdin)
file_close(stream, __FILE_POS__); file_close(stream, __FILE_POS__);
return; return 0;
} }
if (type == IO_IMPORT_ICAL) if (type == IO_IMPORT_ICAL)
@ -1377,8 +1377,11 @@ void io_import_data(enum import_type type, char *stream_name,
mem_free(stats_str[3]); mem_free(stats_str[3]);
if (ui_mode == UI_CURSES) if (ui_mode == UI_CURSES)
mem_free(stream_name); mem_free(stream_name);
if (!stats.skipped) if (!stats.skipped) {
io_log_free(log); io_log_free(log);
return 1;
} else
return 0;
} }
struct io_file *io_log_init(void) struct io_file *io_log_init(void)