diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-04-19 16:31:45 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-04-19 16:31:45 -0400 |
commit | 6d04ff98c4bfc21ad3fa779237a16ba760080fac (patch) | |
tree | e5cdaf218d7fc563899eb44292225fca7f051363 /lib/install.c | |
parent | 57c9489b28a481abc078ad3a2dd197079f9c414b (diff) | |
download | spmc-6d04ff98c4bfc21ad3fa779237a16ba760080fac.tar.gz |
Better reporting when a package does not exist
* Add additional errors
* Fix user_input function missing an error return value
* spmbuild sources a temporary file instead of output from a sub-shell
* Fix indentation problem
* A reason can be attached to spmerrno using spmerrno_cause()
Diffstat (limited to 'lib/install.c')
-rw-r--r-- | lib/install.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/lib/install.c b/lib/install.c index c5c2c4c..32348e2 100644 --- a/lib/install.c +++ b/lib/install.c @@ -200,8 +200,32 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { size_t num_requirements = 0; ManifestPackage **requirements = NULL; char source[PATH_MAX]; - char *tmpdir = spm_mkdtemp(TMP_DIR, "spm_destroot", NULL); + char *tmpdir = NULL; + // Produce a dependency tree from requested package(s) + for (size_t i = 0; i < strlist_count(packages); i++) { + char *item = strlist_item(packages, i); + + // Does the package exist in the manifest? + if (manifestlist_search(mf, item) == NULL) { + spmerrno = SPM_ERR_PKG_NOT_FOUND; + spmerrno_cause(item); + break; + } + + requirements = resolve_dependencies(mf, item); + if (requirements != NULL) { + for (size_t c = num_requirements; requirements[c] != NULL; c++) { + num_requirements++; + } + } + } + + if (spmerrno) { + return -1; + } + + tmpdir = spm_mkdtemp(TMP_DIR, "spm_destroot", NULL); if (tmpdir == NULL) { perror("Could not create temporary destination root"); fprintf(SYSERROR); @@ -214,20 +238,10 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { if (spm_hierarchy_make_root(fs) < 0) { spmerrno = SPM_ERR_ROOT_NO_RECORD; + rmdirs(tmpdir); return -1; } - // Produce a dependency tree from requested package(s) - for (size_t i = 0; i < strlist_count(packages); i++) { - char *item = strlist_item(packages, i); - requirements = resolve_dependencies(mf, item); - if (requirements != NULL) { - for (size_t c = num_requirements; requirements[c] != NULL; c++) { - num_requirements++; - } - } - } - // Install packages printf("Requested package(s):\n"); for (size_t i = 0; requirements !=NULL && requirements[i] != NULL; i++) { @@ -244,7 +258,7 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { char *package_dir = strdup(SPM_GLOBAL.package_dir); for (size_t i = 0; requirements != NULL && requirements[i] != NULL; i++) { char *package_origin = calloc(PATH_MAX, sizeof(char)); - strncpy(package_origin, requirements[i]->origin, PATH_MAX); + strncpy(package_origin, requirements[i]->origin, PATH_MAX); if (strstr(package_origin, SPM_GLOBAL.repo_target) == NULL) { if (!endswith(package_origin, DIRSEPS)) { |