< 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,13 +32,15 @@
 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.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,11 +57,11 @@
 /**
  * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal
  */
 final class ZipPath implements Path {
 
-    private final ZipFileSystem zfs;
+    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,25 +756,35 @@
             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);
+        ZipFileAttributeView.get(this, type).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)
+    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,15 +792,11 @@
             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);
+        return ZipFileAttributeView.get(this, view).readAttributes(attrs);
     }
 
     FileStore getFileStore() throws IOException {
         // each ZipFileSystem only has one root (as requested for now)
         if (exists())

@@ -933,16 +941,18 @@
             } finally {
                 is.close();
             }
         }
         if (copyAttrs) {
-            BasicFileAttributeView view =
-                ZipFileAttributeView.get(target, BasicFileAttributeView.class);
+            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 >