diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2017-09-08 07:41:58 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2017-09-08 21:08:54 +0200 |
commit | ba85d9b6f5e9854c7d4ec47e2a91b53e7f454f21 (patch) | |
tree | 24f7a65ca4c3b96772a1a4544a22023ecd4b97f4 /src | |
parent | 9137590e7a6e29f9d3d512bc8e64e38a850fbef6 (diff) | |
download | calcurse-ba85d9b6f5e9854c7d4ec47e2a91b53e7f454f21.tar.gz calcurse-ba85d9b6f5e9854c7d4ec47e2a91b53e7f454f21.zip |
Factor out check for external modifications
Move the check to compare the stored hashes of the data files with the
current hash to a separate function. This makes the code easier to read
and reusable.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/io.c | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -500,36 +500,41 @@ static int resolve_save_conflict(void) return ret; } -/* Save the calendar data */ -void io_save_cal(enum save_display display) +static int io_check_data_files_modified() { - const char *access_pb = _("Problems accessing data file ..."); - const char *save_success = - _("The data files were successfully saved"); - const char *enter = _("Press [ENTER] to continue"); - int show_bar; FILE *fp; char sha1_new[SHA1_DIGESTLEN * 2 + 1]; - int conflict = 0; - - if (read_only) - return; if ((fp = fopen(path_apts, "r"))) { sha1_stream(fp, sha1_new); fclose(fp); if (strncmp(sha1_new, apts_sha1, SHA1_DIGESTLEN * 2) != 0) - conflict = 1; + return 1; } - if (!conflict && (fp = fopen(path_todo, "r"))) { + if ((fp = fopen(path_todo, "r"))) { sha1_stream(fp, sha1_new); fclose(fp); if (strncmp(sha1_new, todo_sha1, SHA1_DIGESTLEN * 2) != 0) - conflict = 1; + return 1; } - if (conflict && resolve_save_conflict()) + return 0; +} + +/* Save the calendar data */ +void io_save_cal(enum save_display display) +{ + const char *access_pb = _("Problems accessing data file ..."); + const char *save_success = + _("The data files were successfully saved"); + const char *enter = _("Press [ENTER] to continue"); + int show_bar; + + if (read_only) + return; + + if (io_check_data_files_modified() && resolve_save_conflict()) return; run_hook("pre-save"); |