< prev index next >

src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java

Print this page
rev 57904 : 8225507: (zipfs) - No space left on device not thrown with ZipFileSystem
Summary: jdk.nio.zipfs.ZipFileSystem no longer swallows the IOExceptions
Reviewed-by:


1716             for (ExistingChannelCloser ecc : exChClosers) {
1717                 if (ecc.closeAndDeleteIfDone()) {
1718                     exChClosers.remove(ecc);
1719                 }
1720             }
1721         }
1722         if (!hasUpdate)
1723             return;
1724         PosixFileAttributes attrs = getPosixAttributes(zfpath);
1725         Path tmpFile = createTempFileInSameDirectoryAs(zfpath);
1726         try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(tmpFile, WRITE))) {
1727             ArrayList<Entry> elist = new ArrayList<>(inodes.size());
1728             long written = 0;
1729             byte[] buf = null;
1730             Entry e;
1731 
1732             // write loc
1733             for (IndexNode inode : inodes.values()) {
1734                 if (inode instanceof Entry) {    // an updated inode
1735                     e = (Entry)inode;
1736                     try {
1737                         if (e.type == Entry.COPY) {
1738                             // entry copy: the only thing changed is the "name"
1739                             // and "nlen" in LOC header, so we update/rewrite the
1740                             // LOC in new file and simply copy the rest (data and
1741                             // ext) without enflating/deflating from the old zip
1742                             // file LOC entry.
1743                             if (buf == null)
1744                                 buf = new byte[8192];
1745                             written += copyLOCEntry(e, true, os, written, buf);
1746                         } else {                          // NEW, FILECH or CEN
1747                             e.locoff = written;
1748                             written += e.writeLOC(os);    // write loc header
1749                             written += writeEntry(e, os);
1750                         }
1751                         elist.add(e);
1752                     } catch (IOException x) {
1753                         x.printStackTrace();    // skip any in-accurate entry
1754                     }
1755                 } else {                        // unchanged inode
1756                     if (inode.pos == -1) {
1757                         continue;               // pseudo directory node
1758                     }
1759                     if (inode.name.length == 1 && inode.name[0] == '/') {
1760                         continue;               // no root '/' directory even if it
1761                                                 // exists in original zip/jar file.
1762                     }
1763                     e = supportPosix ? new PosixEntry(this, inode) : new Entry(this, inode);
1764                     try {
1765                         if (buf == null)
1766                             buf = new byte[8192];
1767                         written += copyLOCEntry(e, false, os, written, buf);
1768                         elist.add(e);
1769                     } catch (IOException x) {
1770                         x.printStackTrace();    // skip any wrong entry
1771                     }
1772                 }
1773             }
1774 
1775             // now write back the cen and end table
1776             end.cenoff = written;
1777             for (Entry entry : elist) {
1778                 written += entry.writeCEN(os);
1779             }
1780             end.centot = elist.size();
1781             end.cenlen = written - end.cenoff;
1782             end.write(os, written, forceEnd64);
1783         }
1784         if (!streams.isEmpty()) {
1785             //
1786             // There are outstanding input streams open on existing "ch",
1787             // so, don't close the "cha" and delete the "file for now, let
1788             // the "ex-channel-closer" to handle them
1789             Path path = createTempFileInSameDirectoryAs(zfpath);
1790             ExistingChannelCloser ecc = new ExistingChannelCloser(path,
1791                                                                   ch,




1716             for (ExistingChannelCloser ecc : exChClosers) {
1717                 if (ecc.closeAndDeleteIfDone()) {
1718                     exChClosers.remove(ecc);
1719                 }
1720             }
1721         }
1722         if (!hasUpdate)
1723             return;
1724         PosixFileAttributes attrs = getPosixAttributes(zfpath);
1725         Path tmpFile = createTempFileInSameDirectoryAs(zfpath);
1726         try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(tmpFile, WRITE))) {
1727             ArrayList<Entry> elist = new ArrayList<>(inodes.size());
1728             long written = 0;
1729             byte[] buf = null;
1730             Entry e;
1731 
1732             // write loc
1733             for (IndexNode inode : inodes.values()) {
1734                 if (inode instanceof Entry) {    // an updated inode
1735                     e = (Entry)inode;

1736                     if (e.type == Entry.COPY) {
1737                         // entry copy: the only thing changed is the "name"
1738                         // and "nlen" in LOC header, so we update/rewrite the
1739                         // LOC in new file and simply copy the rest (data and
1740                         // ext) without enflating/deflating from the old zip
1741                         // file LOC entry.
1742                         if (buf == null)
1743                             buf = new byte[8192];
1744                         written += copyLOCEntry(e, true, os, written, buf);
1745                     } else {                          // NEW, FILECH or CEN
1746                         e.locoff = written;
1747                         written += e.writeLOC(os);    // write loc header
1748                         written += writeEntry(e, os);
1749                     }
1750                     elist.add(e);



1751                 } else {                        // unchanged inode
1752                     if (inode.pos == -1) {
1753                         continue;               // pseudo directory node
1754                     }
1755                     if (inode.name.length == 1 && inode.name[0] == '/') {
1756                         continue;               // no root '/' directory even if it
1757                                                 // exists in original zip/jar file.
1758                     }
1759                     e = supportPosix ? new PosixEntry(this, inode) : new Entry(this, inode);

1760                     if (buf == null)
1761                         buf = new byte[8192];
1762                     written += copyLOCEntry(e, false, os, written, buf);
1763                     elist.add(e);



1764                 }
1765             }
1766 
1767             // now write back the cen and end table
1768             end.cenoff = written;
1769             for (Entry entry : elist) {
1770                 written += entry.writeCEN(os);
1771             }
1772             end.centot = elist.size();
1773             end.cenlen = written - end.cenoff;
1774             end.write(os, written, forceEnd64);
1775         }
1776         if (!streams.isEmpty()) {
1777             //
1778             // There are outstanding input streams open on existing "ch",
1779             // so, don't close the "cha" and delete the "file for now, let
1780             // the "ex-channel-closer" to handle them
1781             Path path = createTempFileInSameDirectoryAs(zfpath);
1782             ExistingChannelCloser ecc = new ExistingChannelCloser(path,
1783                                                                   ch,


< prev index next >