synk

synchronize files between hosts
Log | Files | Refs | README | LICENSE

commit 66a2949e476739232a5cb7888d118d1f2d6dd5b8
parent 697a309f1a1667cf47385370c18e3387af07c06d
Author: Willy <willyatmailoodotorg>
Date:   Tue Aug 30 22:35:13 +0200

Add syncfile(), the main wrapper function

Diffstat:
synk.c | 39+++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+), 0 deletions(-)
diff --git a/synk.c b/synk.c @@ -340,6 +340,44 @@ syncwithmaster(struct peer_t *master, struct peers_t *plist) return 0; } + +/* + * Check the synchronisation state of a file between mutliple peers, and + * synchronise them if they differ + */ +int +syncfile(struct peers_t *plist, const char *fn) +{ + int ret = -1; + struct metadata_t local; + struct peer_t *tmp = NULL; + struct peer_t *master = NULL; + + memset(&local, 0, sizeof(struct metadata_t)); + if (getmetadata(&local, fn) != 0) + return -1; + + SLIST_FOREACH(tmp, plist, entries) { + if (getpeermeta(tmp, local) != 0) { + printf("%s: couldn't retrieve metadata\n", inet_ntoa(tmp->peer.sin_addr)); + return -1; + } + } + + addpeer(plist, INADDR_LOOPBACK, 0); + tmp = SLIST_FIRST(plist); + + tmp->meta = local; + if (syncstatus(plist) != 0) { + master = freshestpeer(plist); + ret = syncwithmaster(master, plist); + } + + flushpeers(plist); + + return ret; +} + int main(int argc, char *argv[]) { @@ -364,6 +402,7 @@ main(int argc, char *argv[]) switch(mode) { case SYNK_CLIENT: while ((fn = *(argv++)) != NULL) { + syncfile(&plist, fn); } break; case SYNK_SERVER: