repo

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 88f39d240294f086e3fb6d3155cfb398d273038e
parent 88561a75de8adb2f555403958572a5167d9ea575
Author: z3bra <willyatmailoodotorg>
Date:   Sat Dec 10 10:19:38 +0100

Let remote_sync() sync any given filename

Diffstat:
repo.c | 46+++++++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/repo.c b/repo.c @@ -12,9 +12,9 @@ #include "arg.h" -#define LISTFILE "/.list" -#define LOCALREPO "local" -#define REMOTEREPO "http://localhost" +#define LISTFILE ".list" +#define LOCALREPO "local/" +#define REMOTEREPO "http://127.0.0.1/" struct pack { char name[LINE_MAX]; @@ -29,7 +29,7 @@ int mkdir_parents(char *, mode_t); struct pack *pack_load(char *); int local_load(struct packs *, char *); int local_list(char *); -int remote_sync(char *, char *); +int remote_sync(char *, char *, char *); void usage(char *name) @@ -103,7 +103,7 @@ local_load(struct packs *plist, char *local) fn[len] = 0; list = fopen(fn, "r"); if (!list) { - perror("fopen"); + perror(fn); free(fn); return -1; } @@ -130,11 +130,11 @@ local_list(char *local) } int -remote_sync(char *remote, char *local) +remote_sync(char *remote, char *local, char *file) { int ret = 0; ssize_t len; - char *url, *fn; + char *url, *enc, *fn; FILE *list; CURL *c; CURLcode r; @@ -155,24 +155,26 @@ remote_sync(char *remote, char *local) if (!c) return -1; - len = strlen(remote) + strlen(LISTFILE); + enc = curl_easy_escape(c, file, strlen(file)); + //printf("encoded: '%s' -> '%s'\n", file, enc); + len = strlen(remote) + strlen(enc); url = malloc(len + 1); if (!url) { perror("malloc"); ret = -1; goto synccleanup; } - snprintf(url, len + 1, "%s%s", remote, LISTFILE); + snprintf(url, len + 1, "%s%s", remote, enc); url[len] = 0; - len = strlen(local) + strlen(LISTFILE); + len = strlen(local) + strlen(enc); fn = malloc(len + 1); if (!fn) { perror("malloc"); ret = 1; goto synccleanup; } - snprintf(fn, len + 1, "%s%s", local, LISTFILE); + snprintf(fn, len + 1, "%s%s", local, enc); fn[len] = 0; list = fopen(fn, "w"); if (!list) { @@ -185,7 +187,7 @@ remote_sync(char *remote, char *local) curl_easy_setopt(c, CURLOPT_WRITEDATA, list); r = curl_easy_perform(c); if (r != CURLE_OK) - fprintf(stderr, "%s\n", curl_easy_strerror(r)); + fprintf(stderr, "%s: %s\n", url, curl_easy_strerror(r)); synccleanup: if (url) free(url); @@ -200,16 +202,30 @@ synccleanup: int main (int argc, char *argv[]) { - char *argv0; + char *argv0, *n; + struct packs plist; + struct pack *p = NULL; + ARGBEGIN{ case 's': - remote_sync(REMOTEREPO, LOCALREPO); + remote_sync(REMOTEREPO, LOCALREPO, LISTFILE); break; case 'l': local_list(LOCALREPO); - break; + return 0; + break; /* NOREACHED */ default: usage(argv0); }ARGEND; + + while ((n = *(argv++))) { + local_load(&plist, LOCALREPO); + SLIST_FOREACH(p, &plist, entries) { + if (!strncmp(p->name, n, PATH_MAX)) { + remote_sync(REMOTEREPO, LOCALREPO, p->filename); + printf("%s%s\n", LOCALREPO, p->filename); + } + } + } return 0; } \ No newline at end of file