diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-30 16:12:21 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-30 16:12:21 +0530 |
commit | 64a9a4b1624bc9fc97553464490d13556d37bb31 (patch) | |
tree | d6435d699b32d0243e15b6a0b9543481a40d37ac | |
parent | 9114d669352f3739f8c2ca3b78f5d143477c66f6 (diff) |
copy: recursive copy must also create parent directories
-rw-r--r-- | src/copy.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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); |