aboutsummaryrefslogtreecommitdiff
path: root/src/msg.c
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-30 16:13:10 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-30 16:13:10 +0530
commitb7ad35df28dfe0a45f0292ed46b658025b61f9e8 (patch)
treea3cd18bbfdcca9db7f934a860b414cc0445f059b /src/msg.c
parent64a9a4b1624bc9fc97553464490d13556d37bb31 (diff)
msg: add support for static files that are copied without processing
Previously, only files in the assets/ directory would be copied over to dist/. This adds support for the user to define what files they'd like copied over.
Diffstat (limited to 'src/msg.c')
-rw-r--r--src/msg.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/msg.c b/src/msg.c
index d0b1639..0b34e93 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -136,10 +136,31 @@ run(void)
return EXIT_FAILURE;
}
- char *assets_directory;
- asprintf(&assets_directory, "%s/%s", msg->base_directory, ASSETS);
- nftw(assets_directory, copy_recursively, 64, FTW_PHYS | FTW_ACTIONRETVAL);
- free(assets_directory);
+ list_t *static_ = get_wrapped(list_find_corresponding_value_from_ptr_wrapper(
+ config->keys, config->array_values, "static"));
+
+ if (static_ == NULL) {
+ printf("Could not find resources in config.cfg\n");
+ return EXIT_FAILURE;
+ }
+
+ for (size_t i = 0; i < static_->size; i++) {
+ ptr_wrapper_t *value = list_get(static_, i);
+ char *path = NULL;
+ asprintf(&path, "%s/%s", msg->base_directory, (char *) value->ptr);
+
+ struct stat path_stat;
+ stat(path, &path_stat);
+
+ if (S_ISREG(path_stat.st_mode))
+ copy_recursively(path, NULL, FTW_F, NULL);
+ else if (S_ISDIR(path_stat.st_mode)) {
+ printf("%s\n", path);
+ nftw(path, copy_recursively, 64, FTW_PHYS | FTW_ACTIONRETVAL);
+ }
+
+ free(path);
+ }
list_t *resources
= get_wrapped(list_find_corresponding_value_from_ptr_wrapper(