From 7472fcbeb9e935435737cb649a90d23d533c2d5c Mon Sep 17 00:00:00 2001 From: riwiwa Date: Sat, 4 Oct 2025 04:45:55 -0700 Subject: [PATCH] fixed unzipping, 1 error message for creating directory still pops up if dir exists --- muzi.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/muzi.c b/muzi.c index 148ae0d..59801fc 100644 --- a/muzi.c +++ b/muzi.c @@ -8,7 +8,8 @@ #include // TODO: -// - unzip a given .zip archive of spotify data to a directory +// - unzip a given .zip archive of spotify data to a directory WITHOUT ROOT +// PERMS // - for each json file in the directory { // - for each json entry { // - add entry to postgresql db @@ -91,10 +92,18 @@ int extract(const char *path) { continue; } - // Handle directories - if (st.name[strlen(st.name) - 1] == '/') { - mkdir(st.name, 0755); // Create directory if it doesn't exist - continue; + // Create directories from zip file + char *search = strchr(st.name, '/'); + if (search != NULL) { + int index = search - st.name; + int end = 0; + char dir[strlen(st.name)]; + for (int j = 0; j < index; j++) { + dir[j] = st.name[j]; + end = j; + } + dir[end + 1] = '\0'; + mkdir(dir, 0777); } // Open file in archive @@ -126,4 +135,4 @@ int extract(const char *path) { return 0; } -int main(void) { extract("archive.zip"); } +int main(void) { extract("./rileyman35@gmail.com-my_spotify_data.zip"); }