RFR 8213031: (zipfs) Add support for POSIX file permissions

Alan Bateman Alan.Bateman at oracle.com
Fri May 31 16:32:53 UTC 2019

On 29/05/2019 13:16, Langer, Christoph wrote:
> Hi Alan,
>> The table items in L119-150 look fine, we just need to avoid really long
>> lines One minor comment on L123 is that it might be clearer if you drop
>> "created" from the sentence.
>> L48-78 is a "wall of text" and links that I don't think will be easy for
>> most developers to read. Can I provide suggested wording for this part
>> of the spec? I'm just thinking that an alternative wording might help
>> avoid too much iteration on this.
> I have created a new webrev to add some linebreaks and pick up your suggestion to drop the word "created" in L123.
> http://cr.openjdk.java.net/~clanger/webrevs/8213031.12/
> Waiting on your update for the other part.
Attached is alternative wording for the "Support for POSIX file 
permissions" section. My concern with the proposed in webrev.12 is that 
it's dense and not easy to read. It also misses a few things - one 
important one is that access permissions aren't enforced.

So overall I think you've got this feature into reasonable shape (I 
realize it has taken 7 months to get here, this is perhaps a good 
example of something that needs a lot of up front discussion before 
going near the code).


import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFileAttributeView;
import java.util.Set;

  * <h2> POSIX file attributes </h2>
  * <p> A Zip file system supports a file attribute {@link 
FileAttributeView view}
  * named "{@code zip}" that defines the following file attribute:
  * <blockquote>
  * <table class="striped">
  * <caption style="display:none">Supported attributes</caption>
  * <thead>
  *   <tr>
  *     <th scope="col"> Name </th>
  *     <th scope="col"> Type </th>
  *   </tr>
  * </thead>
  * <tbody>
  *  <tr>
  *     <th scope="row"> permissions </th>
  *     <td> {@link Set}<{@link PosixFilePermission}> </td>
  *   </tr>
  * </tbody>
  * </table>
  * </blockquote>
  * The "permissions" attribute is the set of access permissions that 
are optionally
  * stored for entries in a Zip file. The value of the attribute is 
{@code null}
  * for entries that do not have access permissions. Zip file systems do not
  * enforce access permissions.
  * <p> The "permissions" attribute can be read and set using the
  * {@linkplain Files#getAttribute(Path, String, LinkOption...) 
Files.getAttribute} and
  * {@linkplain Files#setAttribute(Path, String, Object, LinkOption...) 
  * methods. The following example uses these methods to read and set 
the attribute:
  * <pre> {@code
  *     Set<PosixFilePermission> perms = Files.getAttribute(entry, 
  *     if (perms == null) {
  *         perms = PosixFilePermissions.fromString("rw-rw-rw-");
  *         Files.setAttribute(entry, "zip:permissions", perms);
  *     }
  * } </pre>
  * <p> In addition to the "{@code zip}" view, a Zip file system 
optionally supports
  * the {@link PosixFileAttributeView POSIX file attribute view} 
("{@code posix}").
  * This view extends the "{@code basic}" view with type safe access to the
  * {@link PosixFileAttributes#owner() owner}, {@link 
PosixFileAttributes#group() group-owner},
  * and {@link PosixFileAttributes#permissions() permissions} 
attributes. The
  * "{@code posix}" view is only supported when the Zip file system is 
created with
  * the provider property "{@code enablePosixFileAttributes}" set to 
"{@code true}".
  * The following creates a file system with this property and reads the 
  * permissions of a file:
  * <pre> {@code
  *     var env = Map.of("enablePosixFileAttributes", "true");
  *     try (FileSystem fs = FileSystems.newFileSystem(file, env) {
  *         Path entry = fs.getPath("entry");
  *         Set<PosixFilePermission> perms = 
  *     }
  * } </pre>
  * <p> The file owner and group owner attributes are not persisted, 
meaning they are
  * not stored in the zip file. The "{@code defaultOwner}" and "{@code 
  * provider properties (listed below) can be used to configure the 
default values
  * for these attributes. If these properties are not set then the file 
  * defaults to the owner of the zip file, and the group owner defaults 
to the
  * zip file's group owner (or the file owner on platforms that don't 
support a
  * group owner).
  * <p> The "{@code permissions}" attribute is not optional in the 
"{@code posix}"
  * view so a default of set of permissions are used for entries that do 
not have
  * access permissions stored in the Zip file. The default set of 
  * is {@link PosixFilePermission#OWNER_READ OWNER_READ}, {@link 
  * OWNER_WRITE} and {@link PosixFilePermission#GROUP_READ GROUP_READ}. 
The default
  * permissions can be configured with the "{@code defaultPermissions}" 
  * described below.

More information about the core-libs-dev mailing list