diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2020-04-19 00:35:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-19 00:35:25 -0400 |
commit | 57c9489b28a481abc078ad3a2dd197079f9c414b (patch) | |
tree | 12cc1ea0186b242a82d87bc2f62142e5decefedb /lib/install.c | |
parent | 59f7d29e2d707373ba1153337dca3279a2e3acc5 (diff) | |
parent | 8cdddbb0f1a8c6eb023cbe732e5701240a54ff3c (diff) | |
download | spmc-57c9489b28a481abc078ad3a2dd197079f9c414b.tar.gz |
Merge pull request #25 from jhunkeler/error-handler-etc
Error handler etc
Diffstat (limited to 'lib/install.c')
-rw-r--r-- | lib/install.c | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/lib/install.c b/lib/install.c index c6e12ca..c5c2c4c 100644 --- a/lib/install.c +++ b/lib/install.c @@ -4,6 +4,37 @@ #include <url.h> #include "spm.h" +/** + * Check for the existence of `$ROOT/var/.spm_root` + * @param path + * @return yes=1, no=0 + */ +int spm_hierarchy_is_root(SPM_Hierarchy *fs) { + if (exists(fs->rootrec) != 0) { + return 0; + } + return 1; +} + +/** + * Initialize (not populate) a spm root directory. + * A "root record" is dropped into $ROOT/var + * @param fs `SPM_Hierarchy` structure + * @return success=0, error=-1 + */ +int spm_hierarchy_make_root(SPM_Hierarchy *fs) { + // Create the root directory if it does not exist + if (mkdirs(fs->rootdir, 0755) != 0) { + return -1; + } + + if (touch(fs->rootrec) < 0) { + return -1; + } + + return 0; +} + void spm_install_show_package(ManifestPackage *package) { if (package == NULL) { fprintf(stderr, "ERROR: package was NULL\n"); @@ -27,17 +58,6 @@ int spm_install(SPM_Hierarchy *fs, const char *tmpdir, const char *_package) { return -1; } - if (exists(fs->rootdir) != 0) { - if (SPM_GLOBAL.verbose) { - printf("Creating destination root: %s\n", fs->rootdir); - } - if (mkdirs(fs->rootdir, 0755) != 0) { - fprintf(SYSERROR); - free(package); - return -2; - } - } - if (SPM_GLOBAL.verbose) { printf("Extracting archive: %s\n", package); } @@ -192,6 +212,11 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { printf("Installation root: %s\n", fs->rootdir); } + if (spm_hierarchy_make_root(fs) < 0) { + spmerrno = SPM_ERR_ROOT_NO_RECORD; + 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); @@ -272,6 +297,12 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { manifest_free(tmp_manifest); } + if (spm_hierarchy_is_root(fs) == 0) { + if (SPM_GLOBAL.verbose) { + printf("Creating destination root: %s\n", fs->rootdir); + } + } + printf("Installing package(s):\n"); size_t num_installed = 0; for (size_t i = 0; requirements != NULL && requirements[i] != NULL; i++) { @@ -288,7 +319,6 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { // Relocate installation root relocate_root(fs->rootdir, tmpdir); - spm_install_package_record(fs, tmpdir, requirements[i]->name); num_installed++; free(package_path); |