From 9f02c523512f2de2adf9d219c0e819abfbfa7724 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Sun, 25 Jan 2026 17:29:53 +0100 Subject: Re-organize the sync detection routine --- src/main.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 168860f..04e4d90 100644 --- a/src/main.c +++ b/src/main.c @@ -1074,7 +1074,11 @@ static void ftag_query(int argc, char **argv) free(tags); } -static void ftag_sync(int argc, char **argv) +/* Return: + * - positive value if local ftag database is newer than the remote one; + * - zero if both ftag databases have the same last modification time; + * - negative value if remote ftag database is newer than the local one. */ +static int ftag_sync_compare_mtimes(void) { char *remote_path = FTAG_REMOTE_ROOT "/ftag.sqlite3"; char cmd[1024]; @@ -1104,10 +1108,24 @@ static void ftag_sync(int argc, char **argv) struct stat st; rc = stat(DATABASE_PATH, &st); time_t local_mtime = st.st_mtim.tv_sec; - if (local_mtime > remote_mtime) - printf("ftag sync: local is more recent than remote !\n"); - else - printf("ftag sync: remote is more recent than local !\n"); + return local_time - remote_time; +} + +static int ftag_sync_is_local_newer(void) +{ + return ftag_sync_compare_mtimes() > 0; +} + +static int ftag_sync_is_remote_newer(void) +{ + return ftag_sync_compare_mtimes() < 0; +} + +static void ftag_sync_pull(int argc, char **argv) +{ + if (!ftag_sync_is_remote_newer()) + return; + /* TODO: resume here */ } /* Check that the tag we are trying to create does not exist yet. If this -- cgit v1.2.3