Skip to content

Commit 92b2633

Browse files
committed
8239556: (zipfs) remove ExistingChannelCloser facility in zipfs implementation
Reviewed-by: lancea
1 parent 6c0e3ae commit 92b2633

File tree

1 file changed

+4
-59
lines changed

1 file changed

+4
-59
lines changed

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

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ SeekableByteChannel newByteChannel(byte[] path,
914914
checkWritable();
915915
beginRead(); // only need a read lock, the "update()" will obtain
916916
// the write lock when the channel is closed
917+
ensureOpen();
917918
try {
918919
Entry e = getEntry(path);
919920
if (e != null) {
@@ -1075,7 +1076,7 @@ public long read(ByteBuffer[] dsts, int offset, int length)
10751076
}
10761077
public int write(ByteBuffer src, long position)
10771078
throws IOException
1078-
{
1079+
{
10791080
return fch.write(src, position);
10801081
}
10811082
public MappedByteBuffer map(MapMode mode,
@@ -1114,10 +1115,6 @@ protected void implCloseChannel() throws IOException {
11141115
private Set<InputStream> streams =
11151116
Collections.synchronizedSet(new HashSet<>());
11161117

1117-
// the ex-channel and ex-path that need to close when their outstanding
1118-
// input streams are all closed by the obtainers.
1119-
private final Set<ExistingChannelCloser> exChClosers = new HashSet<>();
1120-
11211118
private final Set<Path> tmppaths = Collections.synchronizedSet(new HashSet<>());
11221119
private Path getTempPathForEntry(byte[] path) throws IOException {
11231120
Path tmpPath = createTempFileInSameDirectoryAs(zfpath);
@@ -1711,14 +1708,6 @@ private void writeTo(Entry e, OutputStream os) throws IOException {
17111708

17121709
// sync the zip file system, if there is any update
17131710
private void sync() throws IOException {
1714-
// check ex-closer
1715-
if (!exChClosers.isEmpty()) {
1716-
for (ExistingChannelCloser ecc : exChClosers) {
1717-
if (ecc.closeAndDeleteIfDone()) {
1718-
exChClosers.remove(ecc);
1719-
}
1720-
}
1721-
}
17221711
if (!hasUpdate)
17231712
return;
17241713
PosixFileAttributes attrs = getPosixAttributes(zfpath);
@@ -1781,22 +1770,8 @@ private void sync() throws IOException {
17811770
end.cenlen = written - end.cenoff;
17821771
end.write(os, written, forceEnd64);
17831772
}
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,
1792-
streams);
1793-
Files.move(zfpath, path, REPLACE_EXISTING);
1794-
exChClosers.add(ecc);
1795-
streams = Collections.synchronizedSet(new HashSet<>());
1796-
} else {
1797-
ch.close();
1798-
Files.delete(zfpath);
1799-
}
1773+
ch.close();
1774+
Files.delete(zfpath);
18001775

18011776
// Set the POSIX permissions of the original Zip File if available
18021777
// before moving the temp file
@@ -3141,36 +3116,6 @@ public Set<PosixFilePermission> permissions() {
31413116
}
31423117
}
31433118

3144-
private static class ExistingChannelCloser {
3145-
private final Path path;
3146-
private final SeekableByteChannel ch;
3147-
private final Set<InputStream> streams;
3148-
ExistingChannelCloser(Path path,
3149-
SeekableByteChannel ch,
3150-
Set<InputStream> streams) {
3151-
this.path = path;
3152-
this.ch = ch;
3153-
this.streams = streams;
3154-
}
3155-
3156-
/**
3157-
* If there are no more outstanding streams, close the channel and
3158-
* delete the backing file
3159-
*
3160-
* @return true if we're done and closed the backing file,
3161-
* otherwise false
3162-
* @throws IOException
3163-
*/
3164-
private boolean closeAndDeleteIfDone() throws IOException {
3165-
if (streams.isEmpty()) {
3166-
ch.close();
3167-
Files.delete(path);
3168-
return true;
3169-
}
3170-
return false;
3171-
}
3172-
}
3173-
31743119
// purely for parent lookup, so we don't have to copy the parent
31753120
// name every time
31763121
static class ParentLookup extends IndexNode {

0 commit comments

Comments
 (0)