diff options
| author | Tristan Riehs <tristan.riehs@inria.fr> | 2026-01-25 17:29:53 +0100 |
|---|---|---|
| committer | Tristan Riehs <tristan.riehs@inria.fr> | 2026-01-25 17:30:19 +0100 |
| commit | 9f02c523512f2de2adf9d219c0e819abfbfa7724 (patch) | |
| tree | 41de58ed4bee77c87fbba441b1f204f44cd7f228 | |
| parent | 84b7c361e22adced611257b4e0859b4ec7e5cd2d (diff) | |
Re-organize the sync detection routine
| -rw-r--r-- | src/main.c | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -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 |
