tAdd syncfile(), the main wrapper function - synk - synchronize files between hosts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 66a2949e476739232a5cb7888d118d1f2d6dd5b8
 (DIR) parent 697a309f1a1667cf47385370c18e3387af07c06d
 (HTM) Author: Willy <willyatmailoodotorg>
       Date:   Tue, 30 Aug 2016 22:35:13 +0200
       
       Add syncfile(), the main wrapper function
       
       Diffstat:
         M synk.c                              |      39 +++++++++++++++++++++++++++++++
       
       1 file changed, 39 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/synk.c b/synk.c
       t@@ -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[])
        {
       t@@ -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: