diff options
| author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-11-06 08:55:52 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-06 08:55:52 -0500 | 
| commit | 52e6d0f495023c0aa939bf6b2170ca5ea853202b (patch) | |
| tree | 897a87316c280b6824892368662afcb848de1cf6 /src/cli | |
| parent | 6db1b15b5c62d6fb52825c1d833ac8dfa9a49fbb (diff) | |
| parent | 46ae10e55603b8852612ebe12c7636c2b358bdd6 (diff) | |
| download | stasis-52e6d0f495023c0aa939bf6b2170ca5ea853202b.tar.gz | |
Merge pull request #67 from jhunkeler/safety-and-convenience
Safety and convenience
Diffstat (limited to 'src/cli')
| -rw-r--r-- | src/cli/stasis/stasis_main.c | 5 | ||||
| -rw-r--r-- | src/cli/stasis/system_requirements.c | 7 | ||||
| -rw-r--r-- | src/cli/stasis/system_requirements.h | 2 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/stasis_indexer.c | 31 | 
4 files changed, 17 insertions, 28 deletions
| diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c index 0c02796..e188b2e 100644 --- a/src/cli/stasis/stasis_main.c +++ b/src/cli/stasis/stasis_main.c @@ -133,6 +133,8 @@ int main(int argc, char *argv[]) {      printf(BANNER, VERSION, AUTHOR); +    check_system_path(); +      msg(STASIS_MSG_L1, "Setup\n");      tpl_setup_vars(&ctx); @@ -241,7 +243,6 @@ int main(int argc, char *argv[]) {      msg(STASIS_MSG_L2, "Installing: %s\n", ctx.conda.installer_name);      delivery_install_conda(ctx.conda.installer_path, ctx.storage.conda_install_prefix); -    check_pathvar(&ctx);      msg(STASIS_MSG_L2, "Configuring: %s\n", ctx.storage.conda_install_prefix);      delivery_conda_enable(&ctx, ctx.storage.conda_install_prefix); @@ -395,7 +396,7 @@ int main(int argc, char *argv[]) {      }      if (strlist_count(ctx.conda.pip_packages_defer)) { -        if (!(ctx.conda.wheels_packages = delivery_build_wheels(&ctx))) { +        if (!((ctx.conda.wheels_packages = delivery_build_wheels(&ctx)))) {              exit(1);          }          if (delivery_index_wheel_artifacts(&ctx)) { diff --git a/src/cli/stasis/system_requirements.c b/src/cli/stasis/system_requirements.c index 53ebbf7..d8d7df3 100644 --- a/src/cli/stasis/system_requirements.c +++ b/src/cli/stasis/system_requirements.c @@ -67,16 +67,11 @@ void check_requirements(struct Delivery *ctx) {      check_system_env_requirements();  } -void check_pathvar(struct Delivery *ctx) { +void check_system_path() {      char *pathvar = NULL;      pathvar = getenv("PATH");      if (!pathvar) {          msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "PATH variable is not set. Cannot continue.\n");          exit(1); -    } else { -        char pathvar_tmp[STASIS_BUFSIZ]; -        sprintf(pathvar_tmp, "%s/bin:%s", ctx->storage.conda_install_prefix, pathvar); -        setenv("PATH", pathvar_tmp, 1); -        pathvar = NULL;      }  }
\ No newline at end of file diff --git a/src/cli/stasis/system_requirements.h b/src/cli/stasis/system_requirements.h index 3a6fa25..ddc2705 100644 --- a/src/cli/stasis/system_requirements.h +++ b/src/cli/stasis/system_requirements.h @@ -5,9 +5,9 @@  #include "callbacks.h"  #include "envctl.h" +void check_system_path();  void check_system_env_requirements();  void check_system_requirements(struct Delivery *ctx);  void check_requirements(struct Delivery *ctx); -void check_pathvar(struct Delivery *ctx);  #endif //STASIS_SYSTEM_REQUIREMENTS_H diff --git a/src/cli/stasis_indexer/stasis_indexer.c b/src/cli/stasis_indexer/stasis_indexer.c index bd59920..fddf18c 100644 --- a/src/cli/stasis_indexer/stasis_indexer.c +++ b/src/cli/stasis_indexer/stasis_indexer.c @@ -23,15 +23,15 @@ const char *long_options_help[] = {  static void usage(char *name) {      int maxopts = sizeof(long_options) / sizeof(long_options[0]); -    unsigned char *opts = calloc(maxopts + 1, sizeof(char)); +    char *opts = calloc(maxopts + 1, sizeof(char));      for (int i = 0; i < maxopts; i++) { -        opts[i] = long_options[i].val; +        opts[i] = (char) long_options[i].val;      }      printf("usage: %s [-%s] {{STASIS_ROOT}...}\n", name, opts);      guard_free(opts);      for (int i = 0; i < maxopts - 1; i++) { -        char line[255]; +        char line[255] = {0};          sprintf(line, "  --%s  -%c  %-20s", long_options[i].name, long_options[i].val, long_options_help[i]);          puts(line);      } @@ -93,9 +93,8 @@ int indexer_wheels(struct Delivery *ctx) {  int indexer_load_metadata(struct Delivery *ctx, const char *filename) {      char line[STASIS_NAME_MAX] = {0}; -    FILE *fp; -    fp = fopen(filename, "r"); +    FILE *fp = fopen(filename, "r");      if (!fp) {          return -1;      } @@ -179,9 +178,8 @@ int indexer_get_files(struct StrList **out, const char *path, const char *patter          char *item = strlist_item(list, i);          if (fnmatch(userpattern, item, 0)) {              no_match++; -            continue;          } else { -            strlist_append(&(*out), item); +            strlist_append((out), item);          }      }      if (no_match >= strlist_count(list)) { @@ -254,7 +252,7 @@ int get_pandoc_version(size_t *result) {          }          size_t parts_total; -        for (parts_total = 0; parts[parts_total] != NULL; parts_total++); +        for (parts_total = 0; parts[parts_total] != NULL; parts_total++) {}          // generate the version as an integer          // note: pandoc version scheme never exceeds four elements (or bytes in this case) @@ -276,7 +274,6 @@ int get_pandoc_version(size_t *result) {  }  int indexer_make_website(struct Delivery *ctx) { -    char cmd[PATH_MAX];      const char *pattern = "*.md";      if (!find_program("pandoc")) { @@ -334,6 +331,7 @@ int indexer_make_website(struct Delivery *ctx) {          }          char *root = strlist_item(dirs, i);          for (size_t x = 0; x < strlist_count(inputs); x++) { +            char cmd[PATH_MAX] = {0};              char *filename = strlist_item(inputs, x);              char fullpath_src[PATH_MAX] = {0};              char fullpath_dest[PATH_MAX] = {0}; @@ -524,8 +522,7 @@ int indexer_readmes(struct Delivery ctx[], size_t nelem) {      sprintf(indexfile, "%s/README.md", ctx->storage.delivery_dir);      if (!pushd(ctx->storage.delivery_dir)) { -        FILE *indexfp; -        indexfp = fopen(indexfile, "w+"); +        FILE *indexfp = fopen(indexfile, "w+");          if (!indexfp) {              fprintf(stderr, "Unable to open %s for writing\n", indexfile);              return -1; @@ -604,8 +601,7 @@ int indexer_junitxml_report(struct Delivery ctx[], size_t nelem) {      }      if (!pushd(ctx->storage.results_dir)) { -        FILE *indexfp; -        indexfp = fopen(indexfile, "w+"); +        FILE *indexfp = fopen(indexfile, "w+");          if (!indexfp) {              fprintf(stderr, "Unable to open %s for writing\n", indexfile);              return -1; @@ -814,7 +810,6 @@ int main(int argc, char *argv[]) {          exit(1);      } -    char *workdir;      char workdir_template[PATH_MAX] = {0};      char *system_tmp = getenv("TMPDIR");      if (system_tmp) { @@ -823,7 +818,7 @@ int main(int argc, char *argv[]) {          strcat(workdir_template, "/tmp");      }      strcat(workdir_template, "/stasis-combine.XXXXXX"); -    workdir = mkdtemp(workdir_template); +    char *workdir = mkdtemp(workdir_template);      if (!workdir) {          SYSERROR("Unable to create temporary directory: %s", workdir_template);          exit(1); @@ -832,8 +827,7 @@ int main(int argc, char *argv[]) {          exit(1);      } -    struct Delivery ctx; -    memset(&ctx, 0, sizeof(ctx)); +    struct Delivery ctx = {0};      printf(BANNER, VERSION, AUTHOR); @@ -919,8 +913,7 @@ int main(int argc, char *argv[]) {      }      msg(STASIS_MSG_L1, "Copying indexed delivery to '%s'\n", destdir); -    char cmd[PATH_MAX]; -    memset(cmd, 0, sizeof(cmd)); +    char cmd[PATH_MAX] = {0};      sprintf(cmd, "rsync -ah%s --delete --exclude 'tmp/' --exclude 'tools/' '%s/' '%s/'", globals.verbose ? "v" : "q", workdir, destdir);      guard_free(destdir); | 
