diff options
author | Your Name <you@example.com> | 2022-04-25 16:19:47 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2022-04-25 16:19:47 -0400 |
commit | 9d9292805d5112aaa6cc85364cafd5e702586d9a (patch) | |
tree | 2698f4f4e818a182ac2d1c44c23b9b8d179d6079 /src/lib | |
parent | ddc05ee8fa60ec240d09d1d71a08f9521a1bd8b2 (diff) | |
download | libbible-9d9292805d5112aaa6cc85364cafd5e702586d9a.tar.gz libbible-9d9292805d5112aaa6cc85364cafd5e702586d9a.tar.bz2 libbible-9d9292805d5112aaa6cc85364cafd5e702586d9a.zip |
Fixed issue with installing zips containing directory listings
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/mods.cc | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/lib/mods.cc b/src/lib/mods.cc index 07f48da..979ecbf 100644 --- a/src/lib/mods.cc +++ b/src/lib/mods.cc @@ -170,6 +170,7 @@ bool libbible::installModFromZip(string filename) { unzClose(zipfile); return false; } + cout << "Unzipping " << filename << "\n"; char read_buffer[READ_SIZE]; ulong i; for(i = 0; i < global_info.number_entry; i++) { @@ -179,6 +180,7 @@ bool libbible::installModFromZip(string filename) { return false; } string fname = basedir + string(read_buffer); + cout << "Unpacking " << fname << "\n"; size_t pos = fname.find_last_of(delim); if(pos != string::npos) { string path = fname.substr(0, pos); @@ -189,26 +191,28 @@ bool libbible::installModFromZip(string filename) { unzClose(zipfile); return false; } - FILE *out = fopen(fname.c_str(), "wb"); - if(out == NULL) { - unzCloseCurrentFile(zipfile); - unzClose(zipfile); - return false; - } - int bytesRead; - do { - bytesRead = unzReadCurrentFile(zipfile, read_buffer, READ_SIZE); - if(bytesRead < 0) { - printf("error %d\n", bytesRead); + if(pos != fname.size()-1) { // It is not a directory + FILE *out = fopen(fname.c_str(), "wb"); + if(out == NULL) { unzCloseCurrentFile(zipfile); unzClose(zipfile); return false; } - if(bytesRead > 0) { - fwrite(read_buffer, bytesRead, 1, out); - } - } while(bytesRead > 0); - fclose(out); + int bytesRead; + do { + bytesRead = unzReadCurrentFile(zipfile, read_buffer, READ_SIZE); + if(bytesRead < 0) { + printf("error %d\n", bytesRead); + unzCloseCurrentFile(zipfile); + unzClose(zipfile); + return false; + } + if(bytesRead > 0) { + fwrite(read_buffer, bytesRead, 1, out); + } + } while(bytesRead > 0); + fclose(out); + } unzCloseCurrentFile(zipfile); unzGoToNextFile(zipfile); } |