diff options
-rw-r--r-- | lib/install.c | 16 | ||||
-rw-r--r-- | src/spm.c | 42 |
2 files changed, 52 insertions, 6 deletions
diff --git a/lib/install.c b/lib/install.c index 9fb80c2..282c662 100644 --- a/lib/install.c +++ b/lib/install.c @@ -201,16 +201,24 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { ManifestPackage **requirements = NULL; char source[PATH_MAX]; char *tmpdir = NULL; + size_t package_count; + + package_count = strlist_count(packages); + if (package_count == 0) { + spmerrno = SPM_ERR_PKG_NOT_FOUND; + spmerrno_cause("EMPTY PACKAGE LIST"); + return -1; + } // Produce a dependency tree from requested package(s) - for (size_t i = 0; i < strlist_count(packages); i++) { + for (size_t i = 0; i < package_count; 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; + return -1; } requirements = resolve_dependencies(mf, item); @@ -221,10 +229,6 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { } } - if (spmerrno) { - return -1; - } - tmpdir = spm_mkdtemp(TMP_DIR, "spm_destroot", NULL); if (tmpdir == NULL) { perror("Could not create temporary destination root"); @@ -30,6 +30,15 @@ void usage(const char *program_name) { } extern spm_vars SPM_GLOBAL; + +static int reader_from_file(size_t lineno, char **line) { + (*line) = strip((*line)); + if (isempty((*line)) || startswith((*line), "#") || startswith((*line), ";") || startswith((*line), "//")) { + return 1; // indicate "continue" + } + return 0; // indicate "ok" +} + int main(int argc, char *argv[], char *arge[]) { char *program_name = strdup(argv[0]); @@ -156,6 +165,39 @@ int main(int argc, char *argv[], char *arge[]) { strlist_append(packages, argv[i]); } } + else if (strcmp(arg, "-F") == 0 || strcmp(arg, "--from-file") == 0) { + RUNTIME_INSTALL = 1; + i++; + char **from_file = NULL; + char *next = argv[i]; + char *filename = calloc(PATH_MAX, sizeof(char)); + + if (next == NULL || (startswith(next, "-") || startswith(next, "--"))) { + fprintf(stderr, "-F|--from-file requires a file path\n"); + usage(program_name); + exit(1); + } + + filename = expandpath(next); + if (exists(filename) != 0) { + perror(filename); + exit(1); + } + + from_file = file_readlines(filename, 0, 0, reader_from_file); + + if (from_file == NULL) { + perror(filename); + exit(1); + } + + for (size_t record = 0; from_file[record] != NULL; record++) { + strlist_append(packages, from_file[record]); + free(from_file[record]); + } + free(from_file); + free(filename); + } else if (strcmp(arg, "-I") == 0 || strcmp(arg, "--install") == 0) { RUNTIME_INSTALL = 1; for (int p = 0; i < argc; p++) { |