From 41021e56c4b5e8d35483929f9b1cd28e1eae0ee7 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Fri, 25 Feb 2022 13:00:12 -0500 Subject: All files are now checked for proper existing directories regardless of directory entries in the zip file. --- zwrapper.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/zwrapper.c b/zwrapper.c index 3d73835..b4d5f89 100644 --- a/zwrapper.c +++ b/zwrapper.c @@ -61,6 +61,50 @@ char *fix; } +void ensure_directory(const char *base, const char *filename) +{ +char *onedir; +char *fulldir; +char *tmp; + + if(filename == NULL || base == NULL) return; + if(strlen(filename) == 0) return; + + onedir = (char *)malloc((strlen(filename)+1)*sizeof(char)); + fulldir = (char *)malloc((strlen(filename)+strlen(base)+2)*sizeof(char)); + + strcpy(onedir, filename); + tmp = onedir; + + tmp = strchr(onedir, pathsep); +#ifdef WIN32 + if(tmp == NULL) + tmp = strchr(onedir, '/'); +#endif + + while(tmp != NULL) { + + *tmp = '\0'; + + gen_full_filename(base, onedir, fulldir, (strlen(filename)+strlen(base)+2)); + makedir(fulldir); + + *tmp = pathsep; + tmp++; +#ifdef WIN32 + if(strchr(tmp, pathsep) == NULL) + tmp = strchr(tmp, '/'); + else + tmp = strchr(tmp, pathsep); +#else + tmp = strchr(tmp, pathsep); +#endif + } + + free(onedir); + free(fulldir); +} + int unzip_file(const char *filename, const char *directory, const char *index_of_files_file) { struct zip *za; @@ -94,6 +138,9 @@ FILE *fp_index; makedir(fullfile); } else { + + ensure_directory(directory, sb.name); + zf = zip_fopen_index(za, i, 0); fp = fopen(fullfile, "wb"); if(zf != NULL && fp != NULL) { -- cgit v1.2.3