aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--include/mirrors.h2
-rw-r--r--lib/archive.c4
-rw-r--r--lib/install.c6
-rw-r--r--lib/internal_cmd.c49
-rw-r--r--lib/manifest.c14
-rw-r--r--lib/mirrors.c25
-rw-r--r--src/spm.c10
7 files changed, 76 insertions, 34 deletions
diff --git a/include/mirrors.h b/include/mirrors.h
index dd4b256..f57da83 100644
--- a/include/mirrors.h
+++ b/include/mirrors.h
@@ -9,6 +9,6 @@
char **mirror_list(const char *filename);
void mirror_list_free(char **m);
-void mirror_clone(Manifest *info, char *dest);
+int mirror_clone(Manifest *info, char *_dest);
#endif //SPM_MIRRORS_H
diff --git a/lib/archive.c b/lib/archive.c
index 18f0437..6452647 100644
--- a/lib/archive.c
+++ b/lib/archive.c
@@ -102,6 +102,10 @@ int tar_extract_archive(const char *_archive, const char *_destination) {
}
status = proc->returncode;
+ if (status != 0 && SPM_GLOBAL.verbose) {
+ fprintf(stderr, "%s", proc->output);
+ }
+
shell_free(proc);
free(archive);
free(destination);
diff --git a/lib/install.c b/lib/install.c
index 8930362..f0fb019 100644
--- a/lib/install.c
+++ b/lib/install.c
@@ -230,6 +230,7 @@ void spm_show_packages(ManifestList *info) {
* @return success=0, exists=1, error=-1 (general), -2 (unable to create `destroot`)
*/
int spm_install(SPM_Hierarchy *fs, const char *tmpdir, const char *_package) {
+ int status_tar;
char *package = strdup(_package);
if (!package) {
@@ -241,8 +242,9 @@ int spm_install(SPM_Hierarchy *fs, const char *tmpdir, const char *_package) {
printf("Extracting archive: %s\n", package);
}
- if (tar_extract_archive(package, tmpdir) != 0) {
- fprintf(stderr, "%s: %s\n", package, strerror(errno));
+ status_tar = 0;
+ if ((status_tar = tar_extract_archive(package, tmpdir)) != 0) {
+ fprintf(stderr, "Extraction program returned non-zero: %d: %s\n", status_tar, package);
free(package);
return -1;
}
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;
}
/**
diff --git a/lib/manifest.c b/lib/manifest.c
index f84867d..cd51b97 100644
--- a/lib/manifest.c
+++ b/lib/manifest.c
@@ -388,25 +388,17 @@ Manifest *manifest_read(char *file_or_url) {
strcpy(path, SPM_GLOBAL.package_dir);
}
else {
- tmpdir = spm_mkdtemp(TMP_DIR, "spm_manifest_read_XXXXXX", SPM_GLOBAL.repo_target);
+ tmpdir = spm_mkdtemp(TMP_DIR, "spm_manifest_read_XXXXXX", NULL);
if (exists(tmpdir) != 0) {
fprintf(stderr, "Failed to create temporary storage directory\n");
fprintf(SYSERROR);
return NULL;
}
- snprintf(pathptr, PATH_MAX - 1, "%s%s%s%s%s", tmpdir, DIRSEPS, SPM_GLOBAL.repo_target, DIRSEPS, filename);
+ pathptr = join((char *[]) {tmpdir, filename, NULL}, DIRSEPS);
}
- const char *target_is;
- if (strstr(file_or_url, SPM_GLOBAL.repo_target) != NULL) {
- target_is = "";
- }
- else {
- target_is = SPM_GLOBAL.repo_target;
- }
-
- char *remote_manifest = join_ex(DIRSEPS, file_or_url, target_is, filename, NULL);
+ char *remote_manifest = join_ex(DIRSEPS, file_or_url, filename, NULL);
if (exists(pathptr) != 0) {
// TODO: Move this out
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
diff --git a/src/spm.c b/src/spm.c
index bb03094..2c2b447 100644
--- a/src/spm.c
+++ b/src/spm.c
@@ -94,12 +94,14 @@ int main(int argc, char *argv[], char *arge[]) {
override_manifests = 1;
}
else if (strcmp(arg, "-m") == 0 || strcmp(arg, "--manifest") == 0) {
+ char *target;
if (arg_next == NULL) {
fprintf(stderr, "-m|--manifest requires a directory path\n");
usage();
exit(1);
}
- manifestlist_append(mf, arg_next);
+ target = join((char *[]) {arg_next, SPM_GLOBAL.repo_target, NULL}, DIRSEPS);
+ manifestlist_append(mf, target);
i++;
}
else if (strcmp(arg, "--reindex") == 0) {
@@ -215,8 +217,12 @@ int main(int argc, char *argv[], char *arge[]) {
// Apply some default manifest locations; unless the user passes -M|--override-manifests
if (override_manifests == 0) {
+ char *target;
// Remote package manifests have priority over the local package store
- manifestlist_append(mf, "https://astroconda.org/spm");
+ target = join((char *[]) {"https://astroconda.org/spm", SPM_GLOBAL.repo_target, NULL}, DIRSEPS);
+ manifestlist_append(mf, target);
+ free(target);
+
// Add the local package store to the bottom
manifestlist_append(mf, SPM_GLOBAL.package_dir);
}