From 460237e94dfead390a7b8372af5c0ebf8c1f226b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 22 Jun 2020 16:11:14 -0400 Subject: Move SPM_GLOBAL.repo_target string usage out of mirror_clone * Assign targets from inside spm.c instead of external manifest/mirror functions --- lib/internal_cmd.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'lib/internal_cmd.c') diff --git a/lib/internal_cmd.c b/lib/internal_cmd.c index 8aa6ab2..3fb383a 100644 --- a/lib/internal_cmd.c +++ b/lib/internal_cmd.c @@ -352,15 +352,52 @@ int mirror_clone_interface(int argc, char **argv) { return -1; } char *url = argv[1]; - char *path = argv[2]; + char *_path = argv[2]; + char *path; + StrList *targets; + char *target_file; + size_t target_count; + int no_mirroring; + + path = NULL; + no_mirroring = 0; + targets = strlist_init(); + target_file = join((char *[]) {url, "spm_mirror.targets", NULL}, DIRSEPS); + + if (strlist_append_file(targets, target_file, NULL) != 0) { + no_mirroring = 1; + } + + if (targets != NULL) { + target_count = strlist_count(targets); + if (target_count == 0) { + no_mirroring = 1; + } + } + + if (no_mirroring) { + fprintf(stderr, "Mirroring is disabled by the server."); + return 1; + } + + for (size_t tgt = 0; tgt < target_count; tgt++) { + char *manifest_location; + char *target; + + target = strlist_item(targets, tgt); + strip(target); - Manifest *manifest = manifest_read(url); - if (manifest == NULL) { - return -2; + manifest_location = join((char *[]) {url, target, NULL}, DIRSEPS); + Manifest *manifest = manifest_read(manifest_location); + if (manifest == NULL) { + return -2; + } + + path = join((char *[]) {_path, target, NULL}, DIRSEPS); + mirror_clone(manifest, path); + manifest_free(manifest); } - mirror_clone(manifest, path); - manifest_free(manifest); return 0; } /** -- cgit