tRecreate local repo upon sync - repo - list/download/sync packs with remote repositories
DIR Log
DIR Files
DIR Refs
DIR README
---
DIR commit 255d98c6c20cb6db83a1a61e7c9bf8d7630baed5
DIR parent 598515bc64f263d554b574f3c4452bb626d3d23b
HTML Author: z3bra <willyatmailoodotorg>
Date: Sat, 10 Dec 2016 09:18:09 +0100
Recreate local repo upon sync
Diffstat:
M repo.c | 41 +++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)
---
DIR diff --git a/repo.c b/repo.c
t@@ -1,7 +1,11 @@
+#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <curl/curl.h>
t@@ -18,6 +22,7 @@ struct pack {
};
void usage(char *);
+int mkdir_parents(char *, mode_t);
int local_list(char *);
int remote_sync(char *, char *);
t@@ -28,6 +33,30 @@ usage(char *name)
exit(1);
}
+/*
+ * Recursive mkdir, taken from the ii project
+ * http://nion.modprobe.de/blog/archives/357-Recursive-directory-creation.html
+ */
+int
+mkdir_parents(char *path, mode_t mode)
+{
+ char tmp[PATH_MAX] = "";
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp), "%s", path);
+ len = strlen(tmp);
+ if(tmp[len - 1] == '/')
+ tmp[len - 1] = 0;
+ for(p = tmp + 1; *p; p++)
+ if(*p == '/') {
+ *p = 0;
+ mkdir(tmp, mode);
+ *p = '/';
+ }
+ return mkdir(tmp, mode);
+}
+
int
local_list(char *local)
{
t@@ -74,6 +103,18 @@ remote_sync(char *remote, char *local)
FILE *list;
CURL *c;
CURLcode r;
+ struct stat sb;
+
+ if (stat(local, &sb) < 0) {
+ switch (errno) {
+ case ENOENT:
+ mkdir_parents(local, 0755);
+ break;
+ default:
+ perror(local);
+ return -1;
+ }
+ }
c = curl_easy_init();
if (!c)