diff options
Diffstat (limited to 'src/copy.c')
-rw-r--r-- | src/copy.c | 82 |
1 files changed, 41 insertions, 41 deletions
@@ -38,53 +38,53 @@ copy_recursively(const char *fpath, int typeflag, struct FTW *ftwbuf) { - (void) sb; - (void) ftwbuf; - - const char *path = fpath + strlen(msg->base_directory) + 1; - char *output_path = NULL; - asprintf(&output_path, "%s/%s", msg->output_directory, path); - - if (typeflag == FTW_D) - goto exit; - - 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, "/"); + (void) sb; + (void) ftwbuf; + + const char *path = fpath + strlen(msg->base_directory) + 1; + char *output_path = NULL; + asprintf(&output_path, "%s/%s", msg->output_directory, path); + + if (typeflag == FTW_D) + goto exit; + + 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); } - strcat(next, token); - mkdir(next, 0700); - } + free(temppath); + free(directory); + free(next); - free(temppath); - free(directory); - free(next); + FILE *in = fopen(fpath, "r"); + size_t size = fsize(in); + fclose(in); - FILE *in = fopen(fpath, "r"); - size_t size = fsize(in); - fclose(in); + int in_fd = open(fpath, O_RDONLY); + int out_fd = open(output_path, O_WRONLY | O_CREAT, 0700); - int in_fd = open(fpath, O_RDONLY); - int out_fd = open(output_path, O_WRONLY | O_CREAT, 0700); + sendfile(out_fd, in_fd, 0, size); - sendfile(out_fd, in_fd, 0, size); - - close(in_fd); - close(out_fd); + close(in_fd); + close(out_fd); exit: - free(output_path); - return FTW_CONTINUE; + free(output_path); + return FTW_CONTINUE; } |