summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2020-11-03 19:28:19 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2020-11-07 19:50:23 -0500
commit97df01b534ac5616f39c1a1ffff8fc8e3e7927f9 (patch)
tree327ca724f3aac97de14180ce63f522b1371d5199
parentd126696999966ebb2456603b047c3950fa4a4eac (diff)
downloadcalcurse-97df01b534ac5616f39c1a1ffff8fc8e3e7927f9.tar.gz
calcurse-97df01b534ac5616f39c1a1ffff8fc8e3e7927f9.zip
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>
-rw-r--r--src/args.c8
-rw-r--r--src/calcurse.h2
-rw-r--r--src/io.c11
3 files changed, 13 insertions, 8 deletions
diff --git a/src/args.c b/src/args.c
index abcc70a..c66c724 100644
--- a/src/args.c
+++ b/src/args.c
@@ -428,7 +428,7 @@ int parse_args(int argc, char **argv)
const char *cfile = NULL, *confdir = NULL;
char *ifile = NULL;
- int non_interactive = 1;
+ int ret, non_interactive = 1;
int ch, cpid, type;
regex_t reg;
char buf[BUFSIZ];
@@ -963,10 +963,12 @@ int parse_args(int argc, char **argv)
fmt_apt = fmt_rapt = fmt_ev = fmt_rev = NULL;
fmt_todo = NULL;
}
- io_import_data(IO_IMPORT_ICAL, ifile, fmt_ev, fmt_rev, fmt_apt,
- fmt_rapt, fmt_todo);
+ ret = io_import_data(IO_IMPORT_ICAL, ifile, fmt_ev, fmt_rev,
+ fmt_apt, fmt_rapt, fmt_todo);
io_save_apts(path_apts);
io_save_todo(path_todo);
+ if (!ret)
+ exit_calcurse(EXIT_FAILURE);
} else if (export) {
io_check_file(path_apts);
io_check_file(path_todo);
diff --git a/src/calcurse.h b/src/calcurse.h
index 763264d..c1ca2ef 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -924,7 +924,7 @@ unsigned io_file_exists(const char *);
int io_check_file(const char *);
int io_check_data_files(void);
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 *);
struct io_file *io_log_init(void);
void io_log_print(struct io_file *, int, const char *);
diff --git a/src/io.c b/src/io.c
index 43c9b28..cd9b389 100644
--- a/src/io.c
+++ b/src/io.c
@@ -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,
* 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_apt, const char *fmt_rapt,
const char *fmt_todo)
@@ -1312,7 +1312,7 @@ void io_import_data(enum import_type type, char *stream_name,
}
if (stream == NULL)
- return;
+ return 0;
memset(&stats, 0, sizeof stats);
@@ -1320,7 +1320,7 @@ void io_import_data(enum import_type type, char *stream_name,
if (log == NULL) {
if (stream != stdin)
file_close(stream, __FILE_POS__);
- return;
+ return 0;
}
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]);
if (ui_mode == UI_CURSES)
mem_free(stream_name);
- if (!stats.skipped)
+ if (!stats.skipped) {
io_log_free(log);
+ return 1;
+ } else
+ return 0;
}
struct io_file *io_log_init(void)