Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350881

Read-only Zip file systems should be supported

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • minimal
    • New configuration property when creating a ZIP file system. Long standing behavior to attempt to create a read-write file system is unchanged. So no compatibility concerns.
    • Java API
    • JDK

      Summary

      The ZIP file system provider is enhanced to support creating the file system in read-only mode.

      Problem

      A java.nio.file.FileSystem can be read-only or read-write. A read-only FileSystem does not allow applications to change the contents of the FileSystem.

      The ZIP file system provider treats the contents of a ZIP or JAR file as a file system. When a ZIP file system is constructed for a multi-release JAR file and the "releaseVersion" property is set to a valid non-null value, the implementation in ZIP file system marks the file system as read-only, thus disallowing updates to the underlying JAR file.

      Similarly, when the underlying ZIP/JAR file is not writable, then the ZIP file system implementation marks the file system as read-only.

      Except for these two cases, there currently is no explicit way for applications to instruct the ZIP file system provider to construct a ZIP file system as read-only.

      Solution

      The ZIP file system provider implementation is enhanced to support a new accessMode environmental parameter. This new parameter allows applications to explicitly construct a ZIP file system in read-write or read-only mode.

      Specification

      src/jdk.zipfs/share/classes/module-info.java

       *   <td>
      - *       If the value is {@code true}, the ZIP file system provider
      - *       creates a new ZIP or JAR file if it does not exist.
      + *       If the value is {@code true}, the ZIP file system provider creates a
      + *       new ZIP or JAR file if it does not exist.
        *   </td>
        * </tr>
        * <tr>
      
      
        *           </li>
        *           <li>
        *               If the value is not {@code "STORED"} or {@code "DEFLATED"}, an
      - *               {@code IllegalArgumentException} will be thrown when the Zip
      - *               filesystem is created.
      + *               {@code IllegalArgumentException} will be thrown when creating the
      + *               ZIP file system.
        *           </li>
        *       </ul>
        *   </td>
      
      
        *           <li>
        *               If the value does not represent a valid
        *               {@linkplain Runtime.Version Java SE Platform version number},
      - *               an {@code IllegalArgumentException} will be thrown.
      + *               an {@code IllegalArgumentException} will be thrown when creating
      + *               the ZIP file system.
        *           </li>
        *       </ul>
        *   </td>
        * </tr>
      + * <tr>
      + *   <th scope="row">accessMode</th>
      + *   <td>{@link java.lang.String}</td>
      + *   <td>null/unset</td>
      + *   <td>
      + *       A value defining the desired access mode of the file system.
      + *       ZIP file systems can be created to allow for <em>read-write</em> or
      + *       <em>read-only</em> access.
      + *       <ul>
      + *           <li>
      + *               If no value is set, the file system is created <em>read-write</em>
      + *               if possible. Use {@link java.nio.file.FileSystem#isReadOnly()
      + *               isReadOnly()} to determine the actual access mode.
      + *           </li>
      + *           <li>
      + *               If the value is {@code "readOnly"}, the file system is created
      + *               <em>read-only</em>, and {@link java.nio.file.FileSystem#isReadOnly()
      + *               isReadOnly()} will always return {@code true}. Creating a
      + *               <em>read-only</em> file system requires the underlying ZIP file to
      + *               already exist.
      + *               Specifying the {@code create} property as {@code true} with the
      + *               {@code accessMode} as {@code readOnly} will cause an {@code
      + *               IllegalArgumentException} to be thrown when creating the ZIP file
      + *               system.
      + *           </li>
      + *           <li>
      + *               If the value is {@code "readWrite"}, the file system is created
      + *               <em>read-write</em>, and {@link java.nio.file.FileSystem#isReadOnly()
      + *               isReadOnly()} will always return {@code false}. If a writable file
      + *               system cannot be created, an {@code IOException} will be thrown
      + *               when creating the ZIP file system.
      + *           </li>
      + *           <li>
      + *               Any other values will cause an {@code IllegalArgumentException}
      + *               to be thrown when creating the ZIP file system.
      + *           </li>
      + *       </ul>
      + *       The {@code accessMode} property has no effect on reported POSIX file
      + *       permissions (in cases where POSIX support is enabled).
      + *   </td>
      + * </tr>
        * </tbody>
        * </table>

            dabeaumo David Beaumont
            dabeaumo David Beaumont
            Alan Bateman, Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: