diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-03-27 15:07:47 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-03-27 15:07:47 -0400 |
commit | a72d5b8e451127606b0a47fb771486cab0e2c275 (patch) | |
tree | 64d5827c4e0dcb0cd0c7ce25e6a33d12985cd053 /src/cli/stasis_indexer/helpers.c | |
parent | f8ed92d6257196869315e29d454e86e13453452e (diff) | |
download | stasis-a72d5b8e451127606b0a47fb771486cab0e2c275.tar.gz |
Add write_manifest() helper
* Store file listing in "TREE"
Diffstat (limited to 'src/cli/stasis_indexer/helpers.c')
-rw-r--r-- | src/cli/stasis_indexer/helpers.c | 34 |
1 files changed, 34 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 |