diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-01-27 16:31:12 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-01-27 16:31:12 -0500 |
commit | 38ef2cc6dff14f37050ea40ae62e4aea9863c805 (patch) | |
tree | cb8bc52c84650398f45186365341f29e7c7fde4e /src/mirrors.c | |
parent | b5919aefd1ca043ca26583f94721fb75c72ec9a4 (diff) | |
download | spmc-38ef2cc6dff14f37050ea40ae62e4aea9863c805.tar.gz |
Bug fixes:
* Fix buffer overflow issue with SHA256 buffer
* Add missing origin to manifest
* Fix missing manifest download
Diffstat (limited to 'src/mirrors.c')
-rw-r--r-- | src/mirrors.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/mirrors.c b/src/mirrors.c index 5c18a1c..6b294aa 100644 --- a/src/mirrors.c +++ b/src/mirrors.c @@ -1,4 +1,5 @@ #include "spm.h" +#include "url.h" char **file_readlines(const char *filename) { FILE *fp = NULL; @@ -69,32 +70,51 @@ char **mirror_list(const char *filename) { return result; } -void mirror_clone(Manifest *info, char *dest) { - if (exists(dest) != 0 && mkdir(dest, 0755) != 0) { +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); + } + + if (exists(dest) != 0 && mkdirs(dest, 0755) != 0) { perror("Unable to create mirror directory"); fprintf(SYSERROR); exit(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 *url = join((char *[]) {info->packages[i]->origin, SPM_GLOBAL.repo_target, info->packages[i]->archive, NULL}, DIRSEPS); + char *archive = join((char *[]) {info->packages[i]->origin, SPM_GLOBAL.repo_target, 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); - char *wtf_orig = checksum; - char *wtf_new = info->packages[i]->checksum_sha256; if (strcmp(checksum, info->packages[i]->checksum_sha256) == 0) { - free(url); + printf("Skipped: %s\n", archive); + free(archive); free(path); continue; } } - printf("Downloading: %s\n", url); - if ((response = fetch(url, path)) >= 400) { - fprintf(stderr, "Failed to retrieve (error: %ld): %s\n", response, url); + printf("Fetch: %s\n", archive); + if ((response = fetch(archive, path)) >= 400) { + fprintf(stderr, "WARNING: HTTP(%ld, %s): %s\n", response, http_response_str(response), archive); } - free(url); + free(archive); free(path); } + + // 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); + printf("done!\n"); }
\ No newline at end of file |