diff options
Diffstat (limited to 'src')
| -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 | 22 | 
3 files changed, 57 insertions, 0 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..2f6808c 100644 --- a/src/cli/stasis_indexer/stasis_indexer_main.c +++ b/src/cli/stasis_indexer/stasis_indexer_main.c @@ -368,6 +368,28 @@ int main(const int argc, char *argv[]) {          }      } +    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); | 
