| 61 | } |
| 62 | |
| 63 | void remove_directory(const char * dir_path) { |
| 64 | |
| 65 | if (!is_directory(dir_path)) { |
| 66 | if (unlink(dir_path) == -1) { |
| 67 | printf("Could not remove file %s\n", dir_path); |
| 68 | } |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | uint64_t path_len = strlen(dir_path); |
| 73 | struct dirent * dir; |
| 74 | DIR * d = opendir(dir_path); |
| 75 | |
| 76 | while ((dir = readdir(d)) != NULL) { |
| 77 | char * entry_name = dir->d_name; |
| 78 | if (!strcmp(entry_name, ".") || !strcmp(entry_name, "..")) { |
| 79 | continue; |
| 80 | } |
| 81 | char * path = concat_path(dir_path, entry_name); |
| 82 | remove_directory(path); |
| 83 | free(path); |
| 84 | } |
| 85 | |
| 86 | rmdir(dir_path); |
| 87 | closedir(d); |
| 88 | } |
| 89 | |
| 90 | int make_dir(const char * path) { |
| 91 | if (!path) return -1; |