< prev index next >

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

Print this page
rev 54189 : 8213031: (zipfs) Add support for POSIX file permissions

*** 32,44 **** import java.net.URI; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; import java.nio.file.*; import java.nio.file.DirectoryStream.Filter; - import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileTime; import java.util.Arrays; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; --- 32,46 ---- import java.net.URI; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; import java.nio.file.*; import java.nio.file.DirectoryStream.Filter; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileTime; + import java.nio.file.attribute.GroupPrincipal; + import java.nio.file.attribute.PosixFilePermission; + import java.nio.file.attribute.UserPrincipal; import java.util.Arrays; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects;
*** 55,65 **** /** * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal */ final class ZipPath implements Path { ! private final ZipFileSystem zfs; private final byte[] path; private volatile int[] offsets; private int hashcode = 0; // cached hashcode (created lazily) ZipPath(ZipFileSystem zfs, byte[] path) { --- 57,67 ---- /** * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal */ final class ZipPath implements Path { ! final ZipFileSystem zfs; private final byte[] path; private volatile int[] offsets; private int hashcode = 0; // cached hashcode (created lazily) ZipPath(ZipFileSystem zfs, byte[] path) {
*** 754,778 **** attr = attribute; } else { type = attribute.substring(0, colonPos++); attr = attribute.substring(colonPos); } ! ZipFileAttributeView view = ZipFileAttributeView.get(this, type); ! if (view == null) ! throw new UnsupportedOperationException("view <" + view + "> is not supported"); ! view.setAttribute(attr, value); } void setTimes(FileTime mtime, FileTime atime, FileTime ctime) throws IOException { zfs.setTimes(getResolvedPath(), mtime, atime, ctime); } ! Map<String, Object> readAttributes(String attributes, LinkOption... options) throws IOException { String view = null; String attrs = null; int colonPos = attributes.indexOf(':'); if (colonPos == -1) { --- 756,790 ---- attr = attribute; } else { type = attribute.substring(0, colonPos++); attr = attribute.substring(colonPos); } ! ZipFileAttributeView.get(this, type).setAttribute(attr, value); } void setTimes(FileTime mtime, FileTime atime, FileTime ctime) throws IOException { zfs.setTimes(getResolvedPath(), mtime, atime, ctime); } ! void setOwner(UserPrincipal owner) throws IOException { ! zfs.setOwner(getResolvedPath(), owner); ! } ! ! void setPermissions(Set<PosixFilePermission> perms) throws IOException + { + zfs.setPermissions(getResolvedPath(), perms); + } + void setGroup(GroupPrincipal group) throws IOException { + zfs.setGroup(getResolvedPath(), group); + } + + Map<String, Object> readAttributes(String attributes, LinkOption... options) + throws IOException { String view = null; String attrs = null; int colonPos = attributes.indexOf(':'); if (colonPos == -1) {
*** 780,794 **** attrs = attributes; } else { view = attributes.substring(0, colonPos++); attrs = attributes.substring(colonPos); } ! ZipFileAttributeView zfv = ZipFileAttributeView.get(this, view); ! if (zfv == null) { ! throw new UnsupportedOperationException("view not supported"); ! } ! return zfv.readAttributes(attrs); } FileStore getFileStore() throws IOException { // each ZipFileSystem only has one root (as requested for now) if (exists()) --- 792,802 ---- attrs = attributes; } else { view = attributes.substring(0, colonPos++); attrs = attributes.substring(colonPos); } ! return ZipFileAttributeView.get(this, view).readAttributes(attrs); } FileStore getFileStore() throws IOException { // each ZipFileSystem only has one root (as requested for now) if (exists())
*** 933,948 **** } finally { is.close(); } } if (copyAttrs) { ! BasicFileAttributeView view = ! ZipFileAttributeView.get(target, BasicFileAttributeView.class); try { view.setTimes(zfas.lastModifiedTime(), zfas.lastAccessTime(), zfas.creationTime()); } catch (IOException x) { // rollback? try { target.delete(); } catch (IOException ignore) { } --- 941,958 ---- } finally { is.close(); } } if (copyAttrs) { ! ZipFileAttributeView view = ! ZipFileAttributeView.get(target, ZipFileAttributeView.class); try { view.setTimes(zfas.lastModifiedTime(), zfas.lastAccessTime(), zfas.creationTime()); + // copy permissions + view.setPermissions(zfas.storedPermissions().orElse(null)); } catch (IOException x) { // rollback? try { target.delete(); } catch (IOException ignore) { }
< prev index next >