Uploaded image for project: 'JSword'
  1. JSword
  2. JS-211

Unzip fails if zip contains dir entries

    Details

      Description

      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?

        Attachments

          Activity

            People

            • Assignee:
              dmsmith DM Smith
              Reporter:
              mjdenham Martin Denham
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: