MobileChromeApps / cordova-plugin-zip

Zip plugin for Cordova apps
Other
168 stars 207 forks source link

Recursive unzip? #12

Open pedronetto opened 10 years ago

pedronetto commented 10 years ago

Hey guys, great job you're doing here! I'd like to ask if the plugin does not currently handle sub-directories or if maybe I'm doing something wrong.

The files in the root directory inside the zip come out ok, but the only sub-directory I have returns an error.

Cheers, rock on!

bshepherdson commented 10 years ago

It definitely unpacks subdirectories for me, we're using it to unpack .crx files (zip files with some extra headers).

Try unzipping your file with your system's zip tool, and make sure it's correctly formed?

pedronetto commented 10 years ago

Hey there, thanks for the quick reply! When I try to unzip it with a File Manager for Android it works fine.

What are these extra headers you are talking about? Maybe that's the key.

pedronetto commented 10 years ago

By the way this is the error LogCat gives me:

01-29 16:53:29.460: E/Zip(32408): An error occurred while unzipping. 01-29 16:53:29.460: E/Zip(32408): java.io.IOException: open failed: EROFS (Read-only file system) 01-29 16:53:29.460: E/Zip(32408): at java.io.File.createNewFile(File.java:948) 01-29 16:53:29.460: E/Zip(32408): at org.apache.cordova.Zip.unzipSync(Zip.java:102) 01-29 16:53:29.460: E/Zip(32408): at org.apache.cordova.Zip.access$0(Zip.java:40) 01-29 16:53:29.460: E/Zip(32408): at org.apache.cordova.Zip$1.run(Zip.java:35) 01-29 16:53:29.460: E/Zip(32408): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 01-29 16:53:29.460: E/Zip(32408): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 01-29 16:53:29.460: E/Zip(32408): at java.lang.Thread.run(Thread.java:856) 01-29 16:53:29.460: E/Zip(32408): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system) 01-29 16:53:29.460: E/Zip(32408): at libcore.io.Posix.open(Native Method) 01-29 16:53:29.460: E/Zip(32408): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 01-29 16:53:29.460: E/Zip(32408): at java.io.File.createNewFile(File.java:941) 01-29 16:53:29.460: E/Zip(32408): ... 6 more

bshepherdson commented 10 years ago

Oh, well that's interesting. It looks like it's trying to unpack the zip on a read-only filesystem, so it can't write out the files. Where are you trying to unpack the zip?

The extra headers for a CRX file won't be influencing this. It's just that if you pass this zip plugin a file whose name ends in .crx, it will skip over the CRX file headers. Then it can hand the Android zip library the zip portion only, since it chokes on the extra headers.

pedronetto commented 10 years ago

Ok, thanks for the explanation on the headers.

About the read-only thing: It's interesting indeed since the exact path in my case is "/storage/emulate/0/MyApp/books/69/", or "/mnt/sdcard/MyApp/books/69/" being "MyApp/books/69/" created by the app at some point. So I guess we have to track which read-only file LogCat is pointing out. But how?

Just so you know, my zip structure is like:

book_69.zip

book.json
(d) resources/

    image1.jpg
    image2.jpg

    (d) english/
        audio1.mp3
        audio2.mp3

    (d) german/
        audio1.mp3
        audio2.mp3

So in the end I have 2 files in the directory "MyApp/books/69/":

Please let me know of any tests you think would help in the diagnosis :)

Cheers!

pedronetto commented 10 years ago

Yup, no deal yet. Any ideas on this, guys? Thanks! :D

pedronetto commented 10 years ago

This plugin worked: https://github.com/michogar/extract-zipfile, maybe it's a good idea to take a look at their code :)