aboutsummaryrefslogtreecommitdiff
path: root/lib/manifest.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-04-19 16:31:45 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-04-19 16:31:45 -0400
commit6d04ff98c4bfc21ad3fa779237a16ba760080fac (patch)
treee5cdaf218d7fc563899eb44292225fca7f051363 /lib/manifest.c
parent57c9489b28a481abc078ad3a2dd197079f9c414b (diff)
downloadspmc-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/manifest.c')
-rw-r--r--lib/manifest.c21
1 files changed, 19 insertions, 2 deletions
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 *));