diff options
| author | Tristan Riehs <tristan.riehs@inria.fr> | 2026-01-24 21:53:18 +0100 |
|---|---|---|
| committer | Tristan Riehs <tristan.riehs@inria.fr> | 2026-01-24 21:53:18 +0100 |
| commit | fcf3d5e45222517d69f3ef10132286897f6805d9 (patch) | |
| tree | 81c3494290a944ab22e2d2a1e506145ed5d68546 | |
| parent | 5e5ef3f401370659fc5180c1c192071f38c1ef8b (diff) | |
Implement synchronisation detection
| -rw-r--r-- | src/main.c | 37 |
1 files changed, 34 insertions, 3 deletions
@@ -1075,13 +1075,44 @@ static void ftag_query(int argc, char **argv) static void ftag_sync(int argc, char **argv) { - struct stat st; char *remote_path = FTAG_REMOTE_ROOT "/ftag.sqlite3"; char cmd[1024]; strbuild(cmd, "ssh %s sh -c 'test -f %s && stat --format=%%Y %s || echo 0'", FTAG_REMOTE_HOST, remote_path, remote_path); - FILE *stream = popen(cmd, "r"); - int rc = stat(DATABASE_PATH, &st); + FILE *pipe = popen(cmd, "r"); + if (!pipe) { + fprintf(stderr, "popen: ssh %s: ", FTAG_REMOTE_HOST); + perror(""); + exit(EXIT_FAILURE); + } + size_t line_size = 32; + char *line = malloc(line_size); + ssize_t line_len; + printf("Output of \"%s\":\n", cmd); + printf("BEGIN\n"); + while ((line_len = getline(&line, &line_size, pipe)) != -1) { + printf("%s", line); + } + printf("END\n"); + if (ferror(pipe)) { + perror("getline"); + exit(EXIT_FAILURE); + } + int rc = pclose(pipe); + if (rc == 1) { + fprintf(stderr, "pclose: ssh %s: ", FTAG_REMOTE_HOST); + perror(""); + exit(EXIT_FAILURE); + } + time_t remote_mtime = atol(line); + free(line); + 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: local is more recent than remote !\n"); } /* Check that the tag we are trying to create does not exist yet. If this |
