diff options
| author | Tristan Riehs <tristan.riehs@inria.fr> | 2026-02-08 12:09:16 +0100 |
|---|---|---|
| committer | Tristan Riehs <tristan.riehs@inria.fr> | 2026-02-08 12:09:16 +0100 |
| commit | ceeac3bc42f99490e8b0027aa69ab195a843adb7 (patch) | |
| tree | a90a4a95e54628df4502184af3eca36f7a93359c | |
| parent | a6df8fe0b343ac8c23cd8ff2c46d28ff750e9f8e (diff) | |
Rework ftag sync
Use rsync rather than scp or ssh, it is more flexible and closer to what
we want: preserving modification time, copying recursively.
| -rw-r--r-- | src/main.c | 73 |
1 files changed, 26 insertions, 47 deletions
@@ -11,7 +11,6 @@ #include <sys/wait.h> #include <time.h> #include <unistd.h> -#include <utime.h> #ifndef FTAG_REMOTE_HOST #define FTAG_REMOTE_HOST "localhost" @@ -19,7 +18,7 @@ #ifndef FTAG_REMOTE_ROOT /* HOME on remote host */ -#define FTAG_REMOTE_ROOT "." +#define FTAG_REMOTE_ROOT "ftag" #endif #define DATABASE_PATH (FTAG_ROOT "/ftag.sqlite3") @@ -1150,62 +1149,42 @@ static void ftag_sync_help(int, char **) puts(" push update the remote database from the local"); } -static void ftag_sync_pull(int, char **) +/* Run rsync to perform either the push or the pull action. If argument PUSH is + * non-zero, perform a push, else perform a pull. */ +static void ftag_sync_run_rsync(int push) { - if (!ftag_sync_is_remote_newer()) - return; - char remote_arg[128]; - strbuild(remote_arg, "%s:%s/%s", - FTAG_REMOTE_HOST, FTAG_REMOTE_ROOT, "ftag.sqlite3"); + char remote_root[128]; + strbuild(remote_root, "%s:%s/", + FTAG_REMOTE_HOST, FTAG_REMOTE_ROOT); + char *first = remote_root; + char *second = FTAG_ROOT "/"; + if (push) { + first = FTAG_ROOT "/"; + second = remote_root; + } char *cmd[] = { - "scp", - remote_arg, - DATABASE_PATH, + "rsync", + "--verbose", /* temporary */ + "--archive", + first, + second, NULL }; ftag_execvp(cmd, 1); - time_t remote_mtime = get_remote_mtime(); - struct utimbuf times = { - .actime = remote_mtime, - .modtime = remote_mtime - }; - int rc = utime(DATABASE_PATH, ×); - if (rc == -1) { - fprintf(stderr, "utime: %s:", DATABASE_PATH); - perror(""); - exit(EXIT_FAILURE); - } +} + +static void ftag_sync_pull(int, char **) +{ + if (!ftag_sync_is_remote_newer()) + return; + ftag_sync_run_rsync(0); } static void ftag_sync_push(int, char **) { if (!ftag_sync_is_local_newer()) return; - char remote_arg[128]; - strbuild(remote_arg, "%s:%s/%s", - FTAG_REMOTE_HOST, FTAG_REMOTE_ROOT, "ftag.sqlite3"); - char *cmd_scp[] = { - "scp", - DATABASE_PATH, - remote_arg, - NULL - }; - ftag_execvp(cmd_scp, 1); - time_t local_mtime = get_local_mtime(); - char mtime_date[64]; - strbuild(mtime_date, "@%ld", local_mtime); - char remote_path[128]; - strbuild(remote_path, "%s/ftag.sqlite3", FTAG_REMOTE_ROOT); - char *cmd_ssh_touch[] = { - "ssh", - FTAG_REMOTE_HOST, - "touch", - "--date", - mtime_date, - remote_path, - NULL - }; - ftag_execvp(cmd_ssh_touch, 1); + ftag_sync_run_rsync(1); } static void ftag_sync(int argc, char **argv) |
