From cd65c3320da08f0518e5e86e4645d836405c266b Mon Sep 17 00:00:00 2001
From: jakob
Date: Sun, 15 Jan 2017 14:11:44 -0500
Subject: Implemented initial support for extracting directories.
---
src/write.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/write.c b/src/write.c
index 6aeb629..7593175 100644
--- a/src/write.c
+++ b/src/write.c
@@ -15,6 +15,8 @@
You should have received a copy of the GNU General Public License
along with Nekopack. If not, see . */
+#include
+#include
#include
#include
#include
@@ -52,6 +54,23 @@ char *pop_file_name(uint32_t key, elif_node *root) {
}
+/* Creates all of the paths in a filename. */
+void make_paths(char *file_name) {
+ /* Max filename size. */
+ char *buffer = calloc(0x100, 1);
+ char *buffer_start = buffer;
+ for (int i = 0; i < 0x100 && file_name[i] != '\0'; i++) {
+ *buffer++ = file_name[i];
+ if (file_name[i] == '/') {
+ *buffer = '\0';
+ printf("Creating directory %s\n", buffer_start);
+ mkdir(buffer_start, 0777);
+ }
+ }
+ free(buffer_start);
+}
+
+
/* Iterates through the linked list of file entries and writes every
entry to disk, according to information specified by the node. */
void write_files(file_node *file_root, elif_node *elif_root, FILE *archive) {
@@ -100,6 +119,7 @@ void write_files(file_node *file_root, elif_node *elif_root, FILE *archive) {
encryption_key, current->key);
}
+ make_paths(file_name);
FILE *output = fopen(file_name, "wb+");
if (output == NULL) {
perror(file_name);
--
cgit v1.3