--- old/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java 2019-03-20 17:22:39.312433600 +0100 +++ new/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java 2019-03-20 17:22:38.289384000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,14 +28,20 @@ import java.io.IOException; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileAttributeView; +import java.nio.file.attribute.FileOwnerAttributeView; import java.nio.file.attribute.FileTime; +import java.nio.file.attribute.GroupPrincipal; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.UserPrincipal; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; /** * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal */ -class ZipFileAttributeView implements BasicFileAttributeView { +class ZipFileAttributeView implements PosixFileAttributeView { private static enum AttrID { size, creationTime, @@ -48,43 +54,67 @@ fileKey, compressedSize, crc, - method + method, + storedPermissions, + owner, + group, + permissions }; + private static enum ViewType { + basic, + owner, + posix, + zip + } + private final ZipPath path; - private final boolean isZipView; + private final ViewType type; - private ZipFileAttributeView(ZipPath path, boolean isZipView) { + private ZipFileAttributeView(ZipPath path, ViewType type) { this.path = path; - this.isZipView = isZipView; + this.type = type; } @SuppressWarnings("unchecked") // Cast to V static V get(ZipPath path, Class type) { - if (type == null) - throw new NullPointerException(); if (type == BasicFileAttributeView.class) - return (V)new ZipFileAttributeView(path, false); + return (V)new ZipFileAttributeView(path, ViewType.basic); if (type == ZipFileAttributeView.class) - return (V)new ZipFileAttributeView(path, true); - return null; + return (V)new ZipFileAttributeView(path, ViewType.zip); + if (path.zfs.supportPosix) { + if (type == PosixFileAttributeView.class) + return (V)new ZipFileAttributeView(path, ViewType.posix); + if (type == FileOwnerAttributeView.class) + return (V)new ZipFileAttributeView(path, ViewType.owner); + } + if (type == null) + throw new NullPointerException(); + throw new UnsupportedOperationException(); } static ZipFileAttributeView get(ZipPath path, String type) { if (type == null) throw new NullPointerException(); - if (type.equals("basic")) - return new ZipFileAttributeView(path, false); - if (type.equals("zip")) - return new ZipFileAttributeView(path, true); - return null; + if (type.equals(ViewType.basic.name())) + return new ZipFileAttributeView(path, ViewType.basic); + if (type.equals(ViewType.zip.name())) + return new ZipFileAttributeView(path, ViewType.zip); + if (path.zfs.supportPosix) { + if (type.equals(ViewType.posix.name())) + return new ZipFileAttributeView(path, ViewType.posix); + if (type.equals(ViewType.owner.name())) + return new ZipFileAttributeView(path, ViewType.owner); + } + throw new UnsupportedOperationException("view <" + type + "> is not supported"); } @Override public String name() { - return isZipView ? "zip" : "basic"; + return type.name(); } + @Override public ZipFileAttributes readAttributes() throws IOException { return path.getAttributes(); } @@ -98,6 +128,27 @@ path.setTimes(lastModifiedTime, lastAccessTime, createTime); } + @Override + public UserPrincipal getOwner() throws IOException { + return readAttributes().owner(); + } + + @Override + public void setOwner(UserPrincipal owner) throws IOException { + path.setOwner(owner); + } + + @Override + public void setPermissions(Set perms) throws IOException { + path.setPermissions(perms); + } + + @Override + public void setGroup(GroupPrincipal group) throws IOException { + path.setGroup(group); + } + + @SuppressWarnings("unchecked") void setAttribute(String attribute, Object value) throws IOException { @@ -108,10 +159,14 @@ setTimes(null, (FileTime)value, null); if (AttrID.valueOf(attribute) == AttrID.creationTime) setTimes(null, null, (FileTime)value); + if (AttrID.valueOf(attribute) == AttrID.permissions || + AttrID.valueOf(attribute) == AttrID.storedPermissions) + setPermissions((Set)value); return; - } catch (IllegalArgumentException x) {} - throw new UnsupportedOperationException("'" + attribute + - "' is unknown or read-only attribute"); + } catch (IllegalArgumentException x) { + throw new UnsupportedOperationException("'" + attribute + + "' is unknown or read-only attribute"); + } } Map readAttributes(String attributes) @@ -136,7 +191,7 @@ return map; } - Object attribute(AttrID id, ZipFileAttributes zfas) { + private Object attribute(AttrID id, ZipFileAttributes zfas) { switch (id) { case size: return zfas.size(); @@ -156,17 +211,40 @@ return zfas.isOther(); case fileKey: return zfas.fileKey(); + case owner: + if (type== ViewType.owner || type == ViewType.posix || type == ViewType.zip) { + return zfas.owner(); + } + break; + case group: + if (type == ViewType.posix || type == ViewType.zip) { + return zfas.group(); + } + break; + case permissions: + if (type == ViewType.posix || type == ViewType.zip) { + return zfas.permissions(); + } + break; case compressedSize: - if (isZipView) + if (type == ViewType.zip) { return zfas.compressedSize(); + } break; case crc: - if (isZipView) + if (type == ViewType.zip) { return zfas.crc(); + } break; case method: - if (isZipView) + if (type == ViewType.zip) { return zfas.method(); + } + break; + case storedPermissions: + if (type == ViewType.zip) { + return zfas.storedPermissions().orElse(null); + } break; } return null;