diff options
| author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2025-03-31 15:53:52 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-31 15:53:52 -0400 | 
| commit | 34cee3ad5258b86dfe60df155636bf929b9d0e13 (patch) | |
| tree | 5c11f2fbdc713ed49b65ce839e0550023ff5f0b2 | |
| parent | 5da81c51855b99bc8118d15dce7b8063af8a9afe (diff) | |
| parent | e817b38090defab01e64bc3516ea474215bfcb09 (diff) | |
| download | stasis-34cee3ad5258b86dfe60df155636bf929b9d0e13.tar.gz | |
Merge pull request #102 from jhunkeler/order-of-battle
Bugs and fixes
| -rw-r--r-- | src/cli/stasis_indexer/helpers.c | 34 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/include/helpers.h | 1 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/stasis_indexer_main.c | 40 | ||||
| -rw-r--r-- | src/lib/core/conda.c | 13 | 
4 files changed, 87 insertions, 1 deletions
diff --git a/src/cli/stasis_indexer/helpers.c b/src/cli/stasis_indexer/helpers.c index 8ae49a3..018a8f6 100644 --- a/src/cli/stasis_indexer/helpers.c +++ b/src/cli/stasis_indexer/helpers.c @@ -356,3 +356,37 @@ int load_metadata(struct Delivery *ctx, const char *filename) {      return 0;  } + +int write_manifest(const char *path, char **exclude_path, FILE *fp) { +    struct dirent *rec = NULL; +    DIR *dp = opendir(path); +    if (!dp) { +        perror(path); +        return -1; +    } +    while ((rec = readdir(dp)) != NULL) { +        if (!strcmp(rec->d_name, ".") || !strcmp(rec->d_name, "..")) { +            continue; +        } +        if (strstr_array(exclude_path, rec->d_name)) { +            continue; +        } +        char filepath[PATH_MAX] = {0}; +        strncpy(filepath, path, PATH_MAX - 1); +        strcat(filepath, "/"); +        strcat(filepath, rec->d_name); +        if (rec->d_type == DT_DIR) { +            write_manifest(filepath, exclude_path, fp); +            continue; +        } + +        char *output = filepath; +        if (!strncmp(output, "./", 2)) { +            output += 2; +        } +        printf("%s\n", output); +        fprintf(fp, "%s\n", output); +    } +    closedir(dp); +    return 0; +}
\ No newline at end of file diff --git a/src/cli/stasis_indexer/include/helpers.h b/src/cli/stasis_indexer/include/helpers.h index 46705d2..9cefc05 100644 --- a/src/cli/stasis_indexer/include/helpers.h +++ b/src/cli/stasis_indexer/include/helpers.h @@ -23,5 +23,6 @@ int get_files(struct StrList **out, const char *path, const char *pattern, ...);  struct StrList *get_docker_images(struct Delivery *ctx, char *pattern);  int load_metadata(struct Delivery *ctx, const char *filename);  int micromamba_configure(const struct Delivery *ctx, struct MicromambaInfo *m); +int write_manifest(const char *path, char **exclude_path, FILE *fp);  #endif //HELPERS_H diff --git a/src/cli/stasis_indexer/stasis_indexer_main.c b/src/cli/stasis_indexer/stasis_indexer_main.c index 5510dac..279af5a 100644 --- a/src/cli/stasis_indexer/stasis_indexer_main.c +++ b/src/cli/stasis_indexer/stasis_indexer_main.c @@ -368,6 +368,46 @@ int main(const int argc, char *argv[]) {          }      } +    const char *revisionfile = "REVISION"; +    msg(STASIS_MSG_L1, "Writing revision file: %s\n", revisionfile); +    if (!pushd(workdir)) { +        FILE *revisionfp = fopen(revisionfile, "w+"); +        if (!revisionfp) { +            SYSERROR("Unable to open revision file for writing: %s", revisionfile); +            rmtree(workdir); +            exit(1); +        } +        fprintf(revisionfp, "%d\n", get_latest_rc(local, strlist_count(metafiles))); +        fclose(revisionfp); +        popd(); +    } else { +        SYSERROR("%s", workdir); +        rmtree(workdir); +        exit(1); +    } + +    const char *manifestfile = "TREE"; +    msg(STASIS_MSG_L1, "Writing manifest: %s\n", manifestfile); +    if (!pushd(workdir)) { +        FILE *manifestfp = fopen(manifestfile, "w+"); +        if (!manifestfp) { +            SYSERROR("Unable to open manifest for writing: %s", manifestfile); +            rmtree(workdir); +            exit(1); +        } +        if (write_manifest(".", (char *[]) {"tools", "build", "tmp", NULL}, manifestfp)) { +            SYSERROR("Unable to write records to manifest: %s", manifestfile); +            rmtree(workdir); +            exit(1); +        } +        fclose(manifestfp); +        popd(); +    } else { +        SYSERROR("%s", workdir); +        rmtree(workdir); +        exit(1); +    } +      msg(STASIS_MSG_L1, "Copying indexed delivery to '%s'\n", destdir);      char cmd[PATH_MAX] = {0};      sprintf(cmd, "rsync -ah%s --delete --exclude 'tmp/' --exclude 'tools/' '%s/' '%s/'", globals.verbose ? "v" : "q", workdir, destdir); diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index 80d280a..9b5c77c 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -500,7 +500,18 @@ int conda_setup_headless() {  int conda_env_create_from_uri(char *name, char *uri) {      char env_command[PATH_MAX]; -    sprintf(env_command, "env create -n %s -f %s", name, uri); +    char *uri_fs = NULL; + +    // Convert a bare system path to a file:// path +    if (!strstr(uri, "://")) { +        uri_fs = calloc(strlen(uri) + strlen("file://") + 1, sizeof(*uri_fs)); +        if (!uri_fs) { +            return -1; +        } +        snprintf(uri_fs, strlen(uri) + strlen("file://") + 1, "%s%s", "file://", uri); +    } +    sprintf(env_command, "env create -n '%s' --file='%s'", name, uri_fs ? uri_fs : uri); +    guard_free(uri_fs);      return conda_exec(env_command);  }  | 
