fixed unzipping, 1 error message for creating directory still pops up if

dir exists
This commit is contained in:
2025-10-04 04:45:55 -07:00
parent 16afb87879
commit 7472fcbeb9

21
muzi.c
View File

@@ -8,7 +8,8 @@
#include <zip.h> #include <zip.h>
// TODO: // 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 file in the directory {
// - for each json entry { // - for each json entry {
// - add entry to postgresql db // - add entry to postgresql db
@@ -91,10 +92,18 @@ int extract(const char *path) {
continue; continue;
} }
// Handle directories // Create directories from zip file
if (st.name[strlen(st.name) - 1] == '/') { char *search = strchr(st.name, '/');
mkdir(st.name, 0755); // Create directory if it doesn't exist if (search != NULL) {
continue; 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 // Open file in archive
@@ -126,4 +135,4 @@ int extract(const char *path) {
return 0; return 0;
} }
int main(void) { extract("archive.zip"); } int main(void) { extract("./rileyman35@gmail.com-my_spotify_data.zip"); }