From a72d5b8e451127606b0a47fb771486cab0e2c275 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 27 Mar 2025 15:07:47 -0400 Subject: Add write_manifest() helper * Store file listing in "TREE" --- src/cli/stasis_indexer/helpers.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/cli/stasis_indexer/helpers.c') 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 -- cgit