diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2020-03-10 00:12:50 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2020-03-22 13:40:28 -0400 |
commit | 467815d465195ac7fe05449e074963585c4eaf9f (patch) | |
tree | 12ac0cdfbc9650435e69e284c7327d40280220ed /src/io.c | |
parent | 80b60d63cb751134e31955836e011a7dc593f4f8 (diff) | |
download | calcurse-467815d465195ac7fe05449e074963585c4eaf9f.tar.gz calcurse-467815d465195ac7fe05449e074963585c4eaf9f.zip |
Improve ical import logging
The log file is not deleted if items were skipped (adresses Github issue #269).
The log file includes the import file name and time.
The import line numbers have been corrected (and tests amended).
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -1247,31 +1247,29 @@ void io_export_data(enum export_type type, int export_uid) } } -static FILE *get_import_stream(enum import_type type) +static FILE *get_import_stream(enum import_type type, char **stream_name) { FILE *stream = NULL; - char *stream_name; const char *ask_fname = _("Enter the file name to import data from:"); const char *wrong_file = _("The file cannot be accessed, please enter another file name."); const char *press_enter = _("Press [ENTER] to continue."); - stream_name = mem_malloc(BUFSIZ); - memset(stream_name, 0, BUFSIZ); + *stream_name = mem_malloc(BUFSIZ); + memset(*stream_name, 0, BUFSIZ); while (stream == NULL) { status_mesg(ask_fname, ""); - if (updatestring(win[STA].p, &stream_name, 0, 1)) { - mem_free(stream_name); + if (updatestring(win[STA].p, stream_name, 0, 1)) { + mem_free(*stream_name); return NULL; } - stream = fopen(stream_name, "r"); + stream = fopen(*stream_name, "r"); if (stream == NULL) { status_mesg(wrong_file, press_enter); keys_wait_for_any_key(win[KEY].p); } } - mem_free(stream_name); return stream; } @@ -1282,7 +1280,7 @@ static FILE *get_import_stream(enum import_type type) * 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, const char *stream_name, +void 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) @@ -1309,7 +1307,7 @@ void io_import_data(enum import_type type, const char *stream_name, "Aborting...")); break; case UI_CURSES: - stream = get_import_stream(type); + stream = get_import_stream(type, &stream_name); break; default: EXIT(_("FATAL ERROR: wrong import mode")); @@ -1329,7 +1327,7 @@ void io_import_data(enum import_type type, const char *stream_name, } if (type == IO_IMPORT_ICAL) - ical_import_data(stream, log->fd, &stats.events, + ical_import_data(stream_name, stream, log->fd, &stats.events, &stats.apoints, &stats.todos, &stats.lines, &stats.skipped, fmt_ev, fmt_rev, fmt_apt, fmt_rapt, fmt_todo); @@ -1380,7 +1378,10 @@ void io_import_data(enum import_type type, const char *stream_name, mem_free(stats_str[1]); mem_free(stats_str[2]); mem_free(stats_str[3]); - io_log_free(log); + if (ui_mode == UI_CURSES) + mem_free(stream_name); + if (!stats.skipped) + io_log_free(log); } struct io_file *io_log_init(void) |