aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@inria.fr>2026-02-07 16:03:53 +0100
committerTristan Riehs <tristan.riehs@inria.fr>2026-02-07 16:03:53 +0100
commit946c403d82b98b06342a26ec7dcd8ab442f2219b (patch)
treec052f5df621edfa2514d4761a0f3557085f8b8b5
parent5f9fd4daa369f54714aca9c3d7c8dea0b06f2f31 (diff)
Rework mtime management
-rw-r--r--src/main.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 20c3a0d..1a56ed2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1083,15 +1083,8 @@ static void ftag_query(int argc, char **argv)
free(tags);
}
-/* 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)
+static time_t get_remote_mtime(void)
{
- /* TODO: create get_mtime routines
-
- This will be useful in pull/push routines implementation. */
char *remote_path = FTAG_REMOTE_ROOT "/ftag.sqlite3";
char cmd[1024];
strbuild(cmd, "ssh %s 'test -f %s && stat --format=%%Y %s || echo 0'",
@@ -1117,20 +1110,29 @@ static int ftag_sync_compare_mtimes(void)
}
time_t remote_mtime = atol(line);
free(line);
+ return remote_mtime;
+}
+
+static time_t get_local_mtime(void)
+{
struct stat st;
rc = stat(DATABASE_PATH, &st);
- time_t local_mtime = st.st_mtim.tv_sec;
- return local_mtime - remote_mtime;
+ if (rc == -1) {
+ fprintf(stderr, "stat: %s: ", DATABASE_PATH);
+ perror("");
+ exit(EXIT_FAILURE);
+ }
+ return st.st_mtim.tv_sec;
}
static int ftag_sync_is_local_newer(void)
{
- return ftag_sync_compare_mtimes() > 0;
+ return get_local_mtime() > get_remote_mtime();
}
static int ftag_sync_is_remote_newer(void)
{
- return ftag_sync_compare_mtimes() < 0;
+ return get_local_mtime() < get_remote_mtime();
}
static void ftag_sync_pull(void)