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 | |
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')
-rw-r--r-- | lib/config_global.c | 10 | ||||
-rw-r--r-- | lib/error_handler.c | 10 | ||||
-rw-r--r-- | lib/install.c | 40 | ||||
-rw-r--r-- | lib/internal_cmd.c | 6 | ||||
-rw-r--r-- | lib/manifest.c | 21 | ||||
-rw-r--r-- | lib/user_input.c | 1 |
6 files changed, 73 insertions, 15 deletions
diff --git a/lib/config_global.c b/lib/config_global.c index e97cddb..52589d4 100644 --- a/lib/config_global.c +++ b/lib/config_global.c @@ -3,6 +3,10 @@ */ #include "spm.h" +// GLOBAL +spm_vars SPM_GLOBAL; + + /** * Get path to user's local configuration directory * (The path will be created if it doesn't exist) @@ -125,7 +129,13 @@ void check_runtime_environment(void) { int bad_rt = 0; char *required[] = { "file", +#if defined(__linux) || defined(__linux__) "patchelf", +#elif defined(__APPLE__) && defined(__MACH__) + "install_name_tool", +#elif defined(__WIN32__) + // TODO: Does windows provide some kind of equivalent? +#endif "objdump", "rsync", "tar", diff --git a/lib/error_handler.c b/lib/error_handler.c index baf56b4..292fa6f 100644 --- a/lib/error_handler.c +++ b/lib/error_handler.c @@ -2,7 +2,13 @@ int spmerrno = 0; static char spmerrbuf[255]; +static char spmerrbuf_reason[255]; +void spmerrno_cause(const char *reason) { + char *buf = spmerrbuf_reason; + sprintf(buf, " (%s)", reason); + return; +} /** * * @param code @@ -18,6 +24,10 @@ char *spm_strerror(int code) { } else { strcpy(buf, SPM_ERR_STRING[SPM_ERR_INDEX(code)]); } + + if (strlen(spmerrbuf_reason)) { + strcat(buf, spmerrbuf_reason); + } return buf; } 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)) { diff --git a/lib/internal_cmd.c b/lib/internal_cmd.c index b1e8faa..e5f875f 100644 --- a/lib/internal_cmd.c +++ b/lib/internal_cmd.c @@ -237,7 +237,13 @@ int mkruntime_interface(int argc, char **argv) { } runtime_set(rt, "CFLAGS", "-I$SPM_INCLUDE $CFLAGS"); +#if defined(__APPLE__) && defined (__MACH__) + runtime_set(rt, "LDFLAGS", "-rpath $SPM_LIB:$SPM_LIB64 -L$SPM_LIB -L$SPM_LIB64 $LDFLAGS"); +#elif defined(__linux) || defined (__linux__) runtime_set(rt, "LDFLAGS", "-Wl,-rpath=$SPM_LIB:$SPM_LIB64 -L$SPM_LIB -L$SPM_LIB64 $LDFLAGS"); +#else + // TODO: Windows? +#endif runtime_export(rt, NULL); runtime_free(rt); diff --git a/lib/manifest.c b/lib/manifest.c index a95b566..1bd90b6 100644 --- a/lib/manifest.c +++ b/lib/manifest.c @@ -440,7 +440,21 @@ Manifest *manifest_read(char *file_or_url) { while (fgets(dptr, BUFSIZ, fp) != NULL) { total_records++; } - total_records--; // header does not count + + if (total_records == 0) { + spmerrno = SPM_ERR_MANIFEST_INVALID; + } else if (total_records == 1) { + spmerrno = SPM_ERR_MANIFEST_EMPTY; + } + + if (spmerrno) { + return NULL; + } + + // There's a header, but don't count it in the total + total_records--; + + // Going to reprocess the file again, so rewind rewind(fp); Manifest *info = (Manifest *)calloc(1, sizeof(Manifest)); @@ -582,10 +596,13 @@ void manifestlist_free(ManifestList *pManifestList) { */ void manifestlist_append(ManifestList *pManifestList, char *path) { Manifest *manifest = manifest_read(path); - if (manifest == NULL) { + if (manifest == NULL && spmerrno == 0) { fprintf(stderr, "Failed to create manifest in memory\n"); fprintf(SYSERROR); exit(1); + } else if (spmerrno == SPM_ERR_MANIFEST_EMPTY || spmerrno == SPM_ERR_MANIFEST_INVALID) { + manifest = calloc(1, sizeof(Manifest)); + manifest->packages = calloc(1, sizeof(ManifestPackage *)); } Manifest **tmp = realloc(pManifestList->data, (pManifestList->num_alloc + 1) * sizeof(Manifest *)); diff --git a/lib/user_input.c b/lib/user_input.c index 416b59f..589a084 100644 --- a/lib/user_input.c +++ b/lib/user_input.c @@ -37,4 +37,5 @@ int spm_prompt_user(const char *msg, int empty_input_is_yes) { } input_count++; } + return -1; } |