aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2017-09-08 20:51:56 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2017-09-08 21:21:11 +0200
commit380124c7a21fc216e760e8b925d8738292b725f8 (patch)
treee2552e80a4f06afe2c428390896ee2f5b24c997e /src
parent7a0134204ebf3fe03ce670348c326521ae48f2ed (diff)
downloadcalcurse-380124c7a21fc216e760e8b925d8738292b725f8.tar.gz
calcurse-380124c7a21fc216e760e8b925d8738292b725f8.zip
Factor out hash computation
Move code to compute the hash of a data file to a separate function. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r--src/io.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/io.c b/src/io.c
index 600993b..4d80e3f 100644
--- a/src/io.c
+++ b/src/io.c
@@ -426,6 +426,18 @@ unsigned io_save_keys(void)
return 1;
}
+static int io_compute_hash(const char *path, char *buf)
+{
+ FILE *fp = fopen(path, "r");
+
+ if (!fp)
+ return 0;
+ sha1_stream(fp, buf);
+ fclose(fp);
+
+ return 1;
+}
+
static void io_merge_data(void)
{
char *path_apts_new, *path_todo_new;
@@ -502,22 +514,17 @@ static int resolve_save_conflict(void)
static int io_check_data_files_modified()
{
- FILE *fp;
char sha1_new[SHA1_DIGESTLEN * 2 + 1];
int ret = 1;
io_mutex_lock();
- if ((fp = fopen(path_apts, "r"))) {
- sha1_stream(fp, sha1_new);
- fclose(fp);
+ if (io_compute_hash(path_apts, sha1_new)) {
if (strncmp(sha1_new, apts_sha1, SHA1_DIGESTLEN * 2) != 0)
goto cleanup;
}
- if ((fp = fopen(path_todo, "r"))) {
- sha1_stream(fp, sha1_new);
- fclose(fp);
+ if (io_compute_hash(path_todo, sha1_new)) {
if (strncmp(sha1_new, todo_sha1, SHA1_DIGESTLEN * 2) != 0)
goto cleanup;
}