< prev index next >

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

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

*** 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.BasicFileAttributeView; ! import java.nio.file.attribute.BasicFileAttributes; ! import java.nio.file.attribute.FileAttribute; ! import java.nio.file.attribute.FileAttributeView; ! 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,42 ---- 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.*; import java.util.Arrays; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects;
*** 709,728 **** --- 705,736 ---- throw new NullPointerException(); if (type == BasicFileAttributeView.class) return (V)new ZipFileAttributeView(this, false); if (type == ZipFileAttributeView.class) return (V)new ZipFileAttributeView(this, true); + if (zfs.supportPosix) { + if (type == PosixFileAttributeView.class) + return (V)new ZipPosixFileAttributeView(this, false); + if (type == FileOwnerAttributeView.class) + return (V)new ZipPosixFileAttributeView(this,true); + } throw new UnsupportedOperationException("view <" + type + "> is not supported"); } private ZipFileAttributeView getFileAttributeView(String type) { if (type == null) throw new NullPointerException(); if ("basic".equals(type)) return new ZipFileAttributeView(this, false); if ("zip".equals(type)) return new ZipFileAttributeView(this, true); + if (zfs.supportPosix) { + if ("posix".equals(type)) + return new ZipPosixFileAttributeView(this, false); + if ("owner".equals(type)) + return new ZipPosixFileAttributeView(this, true); + } throw new UnsupportedOperationException("view <" + type + "> is not supported"); } void createDirectory(FileAttribute<?>... attrs) throws IOException
*** 762,775 **** --- 770,789 ---- return zfas; } @SuppressWarnings("unchecked") // Cast to A <A extends BasicFileAttributes> A readAttributes(Class<A> type) throws IOException { + // unconditionally support BasicFileAttributes and ZipFileAttributes if (type == BasicFileAttributes.class || type == ZipFileAttributes.class) { return (A)readAttributes(); } + // support PosixFileAttributes when activated + if (type == PosixFileAttributes.class && zfs.supportPosix) { + return (A)readAttributes(); + } + throw new UnsupportedOperationException("Attributes of type " + type.getName() + " not supported"); } void setAttribute(String attribute, Object value, LinkOption... options)
*** 792,804 **** throws IOException { zfs.setTimes(getResolvedPath(), mtime, atime, ctime); } ! Map<String, Object> readAttributes(String attributes, LinkOption... options) throws IOException { String view; String attrs; int colonPos = attributes.indexOf(':'); if (colonPos == -1) { --- 806,831 ---- 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; String attrs; int colonPos = attributes.indexOf(':'); if (colonPos == -1) {
*** 946,961 **** os.write(buf, 0, n); } } } if (copyAttrs) { ! BasicFileAttributeView view = ! target.getFileAttributeView(BasicFileAttributeView.class); try { view.setTimes(zfas.lastModifiedTime(), zfas.lastAccessTime(), zfas.creationTime()); } catch (IOException x) { // rollback? try { target.delete(); } catch (IOException ignore) { } --- 973,990 ---- os.write(buf, 0, n); } } } if (copyAttrs) { ! ZipFileAttributeView view = ! target.getFileAttributeView(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 >