aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@inria.fr>2026-01-25 17:29:53 +0100
committerTristan Riehs <tristan.riehs@inria.fr>2026-01-25 17:30:19 +0100
commit9f02c523512f2de2adf9d219c0e819abfbfa7724 (patch)
tree41de58ed4bee77c87fbba441b1f204f44cd7f228
parent84b7c361e22adced611257b4e0859b4ec7e5cd2d (diff)
Re-organize the sync detection routine
-rw-r--r--src/main.c28
1 files 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