tOnly download files when needed - repo - list/download/sync packs with remote repositories
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 849be1f67dcdad023ac817558bf918606a3acf35
 (DIR) parent d9c5e6e1e01b02087fc1a6c209bcf0c857b91eb6
 (HTM) Author: z3bra <willyatmailoodotorg>
       Date:   Fri, 16 Dec 2016 02:41:37 +0100
       
       Only download files when needed
       
       Diffstat:
         M repo.c                              |      12 ++++++++++--
       
       1 file changed, 10 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/repo.c b/repo.c
       t@@ -5,6 +5,8 @@
        #include <stdlib.h>
        #include <string.h>
        #include <sys/queue.h>
       +#include <sys/stat.h>
       +#include <sys/types.h>
        #include <unistd.h>
        
        #include <curl/curl.h>
       t@@ -142,6 +144,7 @@ main (int argc, char *argv[])
                char cfgfile[PATH_MAX] = DEFCFGFILE;
                char  fn[PATH_MAX], url[PATH_MAX];
                FILE *fd;
       +        struct stat sb;
                struct packs plist;
                struct repos rlist;
                struct pack *p = NULL;
       t@@ -201,14 +204,19 @@ main (int argc, char *argv[])
                        TAILQ_FOREACH(p, &plist, entries) {
                                if (!strncmp(p->name, n, PATH_MAX)) {
                                        snprintf(fn, PATH_MAX, "%s/%s", DEFLOCALREPO, basename(p->url));
       +                                if (!stat(fn, &sb)) {
       +                                        puts(fn);
       +                                        continue;
       +                                }
       +
                                        fd = fopen(fn, "w");
                                        if (!fd) {
                                                perror(fn);
       -                                        continue;
       +                                        exit(1);
                                        }
                                        download(p->url, fd);
       -                                puts(fn);
                                        fclose(fd);
       +                                puts(fn);
                                        break;
                                }
                        }