src/share/classes/jdk/nio/zipfs/ZipFileSystem.java
Print this page
@@ -39,10 +39,12 @@
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.nio.file.spi.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
@@ -108,11 +110,13 @@
throw new FileSystemNotFoundException(zfpath.toString());
}
}
// sm and existence check
zfpath.getFileSystem().provider().checkAccess(zfpath, AccessMode.READ);
- if (!Files.isWritable(zfpath))
+ boolean writeable = AccessController.doPrivileged(
+ (PrivilegedAction<Boolean>) () -> Files.isWritable(zfpath));
+ if (!writeable)
this.readOnly = true;
this.zc = ZipCoder.get(nameEncoding);
this.defaultdir = new ZipPath(this, getBytes(defaultDir));
this.ch = Files.newByteChannel(zfpath, READ);
this.cen = initCEN();
@@ -260,13 +264,17 @@
for (InputStream is: copy)
is.close();
}
beginWrite(); // lock and sync
try {
- sync();
+ AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
+ sync(); return null;
+ });
ch.close(); // close the ch just in case no update
- } finally { // and sync dose not close the ch
+ } catch (PrivilegedActionException e) { // and sync dose not close the ch
+ throw (IOException)e.getException();
+ } finally {
endWrite();
}
synchronized (inflaters) {
for (Inflater inf : inflaters)
@@ -279,12 +287,14 @@
IOException ioe = null;
synchronized (tmppaths) {
for (Path p: tmppaths) {
try {
- Files.deleteIfExists(p);
- } catch (IOException x) {
+ AccessController.doPrivileged(
+ (PrivilegedExceptionAction<Boolean>)() -> Files.deleteIfExists(p));
+ } catch (PrivilegedActionException e) {
+ IOException x = (IOException)e.getException();
if (ioe == null)
ioe = x;
else
ioe.addSuppressed(x);
}