aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-30 16:12:21 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-30 16:12:21 +0530
commit64a9a4b1624bc9fc97553464490d13556d37bb31 (patch)
treed6435d699b32d0243e15b6a0b9543481a40d37ac
parent9114d669352f3739f8c2ca3b78f5d143477c66f6 (diff)
copy: recursive copy must also create parent directories
-rw-r--r--src/copy.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/copy.c b/src/copy.c
index e5053bd..41da7c7 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -22,6 +22,7 @@
#include <fcntl.h>
#include <filehandler.h>
#include <ftw.h>
+#include <libgen.h>
#include <msg.h>
#include <stdlib.h>
#include <string.h>
@@ -50,6 +51,27 @@ copy_recursively(const char *fpath,
if (typeflag != FTW_F)
goto exit;
+ char *temppath = strdup(path);
+ char *directory;
+ asprintf(&directory, "%s/%s", msg->output_directory, dirname(temppath));
+ char *next = calloc(strlen(directory) + 1, sizeof(char));
+ strcpy(next, "");
+
+ char *token;
+ for (token = strtok(directory, "/"); token != NULL;
+ token = strtok(NULL, "/")) {
+ if (strcmp(next, "") != 0) {
+ strcat(next, "/");
+ }
+
+ strcat(next, token);
+ mkdir(next, 0700);
+ }
+
+ free(temppath);
+ free(directory);
+ free(next);
+
FILE *in = fopen(fpath, "r");
size_t size = fsize(in);
fclose(in);