[jsword-devel] [JIRA] Created: (JS-211) Unzip fails if zip contains dir entries

Martin Denham (JIRA) jira at crosswire.org
Tue Mar 6 16:08:34 MST 2012


Unzip fails if zip contains dir entries
---------------------------------------

                 Key: JS-211
                 URL: http://www.crosswire.org/bugs/browse/JS-211
             Project: JSword
          Issue Type: Bug
          Components: o.c.common.progress
            Reporter: Martin Denham
            Assignee: DM Smith


I noticed zip failures when installing certain zips from Xiphos a long time ago but have only just worked out the problem.
Here is a typical error:
java.net.MalformedURLException: The URL /mnt/sdcard/Android/data/net.bible.android.activity/files/modules/genbook/rawgenbook/luthersworks could not be created as a directory.
at org.crosswire.common.util.IOUtil.unpackZip(IOUtil.java:78)
at org.crosswire.jsword.book.install.sword.AbstractSwordInstaller$1.run(AbstractSwordInstaller.java:258)

The problem is that this zip contains dir entries and if you look in the second half of IOUtil.unpackZip starting from
                URI child = NetUtil.getURI(entryFile);
you will see that unpackZip code tries to create a file even if the ZipEntry is a dir, and when the dir is created as a file later attempts to unzip real files into the file (which should be a dir) fail.

One simple fix is to wrap the last part of code in "if (!entry.isDirectory()) {" as below:
            if (!entry.isDirectory()) {
                URI child = NetUtil.getURI(entryFile);
    
                OutputStream dataOut = NetUtil.getOutputStream(child);
                InputStream dataIn = zf.getInputStream(entry);
    
                while (true) {
                    int count = dataIn.read(dbuf);
                    if (count == -1) {
                        break;
                    }
                    dataOut.write(dbuf, 0, count);
                }
    
                dataOut.close();
            }

I am thinking of checking in some of these recent fixes if you have no objections?


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jsword-devel mailing list