aboutsummaryrefslogtreecommitdiff
path: root/src/stasis_indexer.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-08-14 19:58:44 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-08-14 19:58:44 -0400
commitcc28606e6f5b37d89d565e5c0e687d2bb109c2e6 (patch)
tree3cc86aacf813f8f93a74247a3e6051dc83e975a8 /src/stasis_indexer.c
parent683b3f78663efcff7a406d8287b78d73f18cc1f1 (diff)
downloadstasis-cc28606e6f5b37d89d565e5c0e687d2bb109c2e6.tar.gz
Handle destination directories more gracefully
* The storage.output_dir is now the storage.root to avoid generating a sub-directory beneath the temporary working directory * The destination directory is created, then resolved by realpath to avoid generating the destination directory within the temporary working directory when a relative path is used as input
Diffstat (limited to 'src/stasis_indexer.c')
-rw-r--r--src/stasis_indexer.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/stasis_indexer.c b/src/stasis_indexer.c
index a7b0fce..bc1e6fe 100644
--- a/src/stasis_indexer.c
+++ b/src/stasis_indexer.c
@@ -508,7 +508,7 @@ void indexer_init_dirs(struct Delivery *ctx, const char *workdir) {
fprintf(stderr, "Failed to configure temporary storage directory\n");
exit(1);
}
- path_store(&ctx->storage.output_dir, PATH_MAX, ctx->storage.root, "output");
+ path_store(&ctx->storage.output_dir, PATH_MAX, ctx->storage.root, "");
path_store(&ctx->storage.tools_dir, PATH_MAX, ctx->storage.output_dir, "tools");
path_store(&globals.conda_install_prefix, PATH_MAX, ctx->storage.tools_dir, "conda");
path_store(&ctx->storage.cfgdump_dir, PATH_MAX, ctx->storage.output_dir, "config");
@@ -542,7 +542,13 @@ int main(int argc, char *argv[]) {
usage(path_basename(argv[0]));
exit(0);
case 'd':
- destdir = strdup(optarg);
+ if (mkdir(optarg, 0755)) {
+ if (errno != 0 && errno != EEXIST) {
+ SYSERROR("Unable to create destination directory, '%s': %s", optarg, strerror(errno));
+ exit(1);
+ }
+ }
+ destdir = realpath(optarg, NULL);
break;
case 'U':
fflush(stdout);
@@ -573,7 +579,13 @@ int main(int argc, char *argv[]) {
}
if (isempty(destdir)) {
- destdir = strdup("output");
+ if (mkdir("output", 0755)) {
+ if (errno != 0 && errno != EEXIST) {
+ SYSERROR("Unable to create destination directory, '%s': %s", "output", strerror(errno));
+ exit(1);
+ }
+ }
+ destdir = realpath("output", NULL);
}
if (!rootdirs || !rootdirs_total) {