aboutsummaryrefslogtreecommitdiff
path: root/lib/mirrors.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-06-23 00:22:29 -0400
committerGitHub <noreply@github.com>2020-06-23 00:22:29 -0400
commitfa17600efcd09bf74954e728047fded3ff0bd0cd (patch)
tree33a5a5a608aaba2752ee3f2188370d315b15864a /lib/mirrors.c
parent62db2a4054a55883e7476750c925cb9d5a72fbc5 (diff)
parent155b25db75ecad4b19fd9a36b1aad64d436925dc (diff)
downloadspmc-fa17600efcd09bf74954e728047fded3ff0bd0cd.tar.gz
Merge pull request #48 from jhunkeler/no-auto-repo_target
Move SPM_GLOBAL.repo_target string usage out of mirror_clone
Diffstat (limited to 'lib/mirrors.c')
-rw-r--r--lib/mirrors.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/mirrors.c b/lib/mirrors.c
index 1c51845..19b3910 100644
--- a/lib/mirrors.c
+++ b/lib/mirrors.c
@@ -48,27 +48,28 @@ void mirror_list_free(char **m) {
free(m);
}
-void mirror_clone(Manifest *info, char *_dest) {
- char *dest = NULL;
- if (endswith(_dest, SPM_GLOBAL.repo_target) != 0) {
- dest = strdup(_dest);
- }
- else {
- dest = join((char *[]) {_dest, SPM_GLOBAL.repo_target, NULL}, DIRSEPS);
+int mirror_clone(Manifest *info, char *_dest) {
+ char *dest;
+ long response;
+
+ response = 0;
+ dest = strdup(_dest);
+ if (dest == NULL) {
+ perror("allocate dest string");
+ return 1;
}
if (exists(dest) != 0 && mkdirs(dest, 0755) != 0) {
perror("Unable to create mirror directory");
fprintf(SYSERROR);
- exit(1);
+ return 1;
}
printf("Remote: %s\n", info->origin);
printf("Local: %s\n", dest);
for (size_t i = 0; i < info->records; i++) {
- long response = 0;
- char *archive = join((char *[]) {info->packages[i]->origin, SPM_GLOBAL.repo_target, info->packages[i]->archive, NULL}, DIRSEPS);
+ char *archive = join((char *[]) {dirname(info->origin), info->packages[i]->archive, NULL}, DIRSEPS);
char *path = join((char *[]) {dest, info->packages[i]->archive, NULL}, DIRSEPS);
if (exists(path) == 0) {
char *checksum = sha256sum(path);
@@ -90,11 +91,11 @@ void mirror_clone(Manifest *info, char *_dest) {
// Now fetch a copy of the physical manifest
char *datafile = join((char *[]) {dest, basename(info->origin), NULL}, DIRSEPS);
- long response = 0;
if ((response = fetch(info->origin, datafile) >= 400)) {
fprintf(stderr, "WARNING: HTTP(%ld, %s): %s\n", response, http_response_str(response), info->origin);
}
+
free(dest);
free(datafile);
- printf("done!\n");
+ return 0;
} \ No newline at end of file