Java Code Examples for java.nio.file.attribute.PosixFileAttributeView#setPermissions()

The following examples show how to use java.nio.file.attribute.PosixFileAttributeView#setPermissions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalFileSystem.java    From xenon with Apache License 2.0 6 votes vote down vote up
@Override
public void setPosixFilePermissions(Path path, Set<PosixFilePermission> permissions) throws XenonException {

    if (permissions == null) {
        throw new IllegalArgumentException("Permissions is null!");
    }

    Path absPath = toAbsolutePath(path);

    assertPathExists(absPath);

    try {
        PosixFileAttributeView view = Files.getFileAttributeView(javaPath(absPath), PosixFileAttributeView.class);
        view.setPermissions(javaPermissions(permissions));
    } catch (IOException e) {
        throw new XenonException(ADAPTOR_NAME, "Failed to set permissions " + absPath, e);
    }
}
 
Example 2
Source File: FileUtils.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Define file posix attribute view on a path/file.
 *
 * @param path Target path
 * @param filePermissions Permissions to apply
 * @param fileOwner File owner
 * @param fileGroup File group
 * @throws IOException If IO error during definition of file attribute view
 */
public static void defineFilePosixAttributeView(final Path path,
        final Set<PosixFilePermission> filePermissions,
        final String fileOwner,
        final String fileGroup) throws IOException {
    final PosixFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    if (view != null) {
        final UserPrincipalLookupService lookupService = FileSystems.getDefault()
                .getUserPrincipalLookupService();
        if (fileOwner != null) {
            final UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(fileOwner);
            if (userPrincipal != null) {
                // If not sudoers member, it will throw Operation not permitted
                // Only processes with an effective user ID equal to the user ID
                // of the file or with appropriate privileges may change the ownership of a file.
                // If _POSIX_CHOWN_RESTRICTED is in effect for path
                view.setOwner(userPrincipal);
            }
        }
        if (fileGroup != null) {
            final GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(fileGroup);
            if (groupPrincipal != null) {
                // The current user id should be members of this group,
                // if not will raise Operation not permitted
                view.setGroup(groupPrincipal);
            }
        }
        if (filePermissions != null) {
            view.setPermissions(filePermissions);
        }
    }
}
 
Example 3
Source File: PosixAttributeProviderTest.java    From jimfs with Apache License 2.0 5 votes vote down vote up
@Test
public void testView() throws IOException {
  file.setAttribute("owner", "owner", createUserPrincipal("user"));

  PosixFileAttributeView view =
      provider.view(
          fileLookup(),
          ImmutableMap.of(
              "basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS),
              "owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
  assertNotNull(view);

  assertThat(view.name()).isEqualTo("posix");
  assertThat(view.getOwner()).isEqualTo(createUserPrincipal("user"));

  PosixFileAttributes attrs = view.readAttributes();
  assertThat(attrs.fileKey()).isEqualTo(0);
  assertThat(attrs.owner()).isEqualTo(createUserPrincipal("user"));
  assertThat(attrs.group()).isEqualTo(createGroupPrincipal("group"));
  assertThat(attrs.permissions()).isEqualTo(PosixFilePermissions.fromString("rw-r--r--"));

  view.setOwner(createUserPrincipal("root"));
  assertThat(view.getOwner()).isEqualTo(createUserPrincipal("root"));
  assertThat(file.getAttribute("owner", "owner")).isEqualTo(createUserPrincipal("root"));

  view.setGroup(createGroupPrincipal("root"));
  assertThat(view.readAttributes().group()).isEqualTo(createGroupPrincipal("root"));
  assertThat(file.getAttribute("posix", "group")).isEqualTo(createGroupPrincipal("root"));

  view.setPermissions(PosixFilePermissions.fromString("rwx------"));
  assertThat(view.readAttributes().permissions())
      .isEqualTo(PosixFilePermissions.fromString("rwx------"));
  assertThat(file.getAttribute("posix", "permissions"))
      .isEqualTo(PosixFilePermissions.fromString("rwx------"));
}
 
Example 4
Source File: PosixJdk7FilePermissionHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void chmod(File f, int mode) throws IOException {
    PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(f.toPath(), PosixFileAttributeView.class);
    fileAttributeView.setPermissions(convertToPermissionsSet(mode));
}
 
Example 5
Source File: PosixJdk7FilePermissionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void chmod(File f, int mode) throws IOException {
    PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(f.toPath(), PosixFileAttributeView.class);
    fileAttributeView.setPermissions(convertToPermissionsSet(mode));
}
 
Example 6
Source File: PosixJdk7FilePermissionHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void chmod(File f, int mode) throws IOException {
    PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(f.toPath(), PosixFileAttributeView.class);
    fileAttributeView.setPermissions(convertToPermissionsSet(mode));
}
 
Example 7
Source File: PosixJdk7FilePermissionHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void chmod(File f, int mode) throws IOException {
    PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(f.toPath(), PosixFileAttributeView.class);
    fileAttributeView.setPermissions(convertToPermissionsSet(mode));
}
 
Example 8
Source File: TarGzExtractorProvider.java    From appengine-plugins-core with Apache License 2.0 4 votes vote down vote up
@Override
public void extract(Path archive, Path destination, ProgressListener progressListener)
    throws IOException {

  progressListener.start(
      "Extracting archive: " + archive.getFileName(), ProgressListener.UNKNOWN);

  String canonicalDestination = destination.toFile().getCanonicalPath();

  GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(Files.newInputStream(archive));
  try (TarArchiveInputStream in = new TarArchiveInputStream(gzipIn)) {
    TarArchiveEntry entry;
    while ((entry = in.getNextTarEntry()) != null) {
      Path entryTarget = destination.resolve(entry.getName());

      String canonicalTarget = entryTarget.toFile().getCanonicalPath();
      if (!canonicalTarget.startsWith(canonicalDestination + File.separator)) {
        throw new IOException("Blocked unzipping files outside destination: " + entry.getName());
      }

      progressListener.update(1);
      logger.fine(entryTarget.toString());

      if (entry.isDirectory()) {
        if (!Files.exists(entryTarget)) {
          Files.createDirectories(entryTarget);
        }
      } else if (entry.isFile()) {
        if (!Files.exists(entryTarget.getParent())) {
          Files.createDirectories(entryTarget.getParent());
        }
        try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(entryTarget))) {
          IOUtils.copy(in, out);
          PosixFileAttributeView attributeView =
              Files.getFileAttributeView(entryTarget, PosixFileAttributeView.class);
          if (attributeView != null) {
            attributeView.setPermissions(PosixUtil.getPosixFilePermissions(entry.getMode()));
          }
        }
      } else {
        // we don't know what kind of entry this is (we only process directories and files).
        logger.warning("Skipping entry (unknown type): " + entry.getName());
      }
    }
    progressListener.done();
  }
}
 
Example 9
Source File: Files.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 10
Source File: Files.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 11
Source File: Files.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 12
Source File: Files.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 13
Source File: Files.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 14
Source File: Files.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 15
Source File: Files.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 16
Source File: Files.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The given path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies
 *          {@link RuntimePermission}{@code ("accessUserInformation")}
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 17
Source File: Files.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The given path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies
 *          {@link RuntimePermission}{@code ("accessUserInformation")}
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 18
Source File: Files.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 19
Source File: Files.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}
 
Example 20
Source File: Files.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets a file's POSIX permissions.
 *
 * <p> The {@code path} parameter is associated with a {@code FileSystem}
 * that supports the {@link PosixFileAttributeView}. This attribute view
 * provides access to file attributes commonly associated with files on file
 * systems used by operating systems that implement the Portable Operating
 * System Interface (POSIX) family of standards.
 *
 * @param   path
 *          The path to the file
 * @param   perms
 *          The new set of permissions
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          PosixFileAttributeView}
 * @throws  ClassCastException
 *          if the sets contains elements that are not of type {@code
 *          PosixFilePermission}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 */
public static Path setPosixFilePermissions(Path path,
                                           Set<PosixFilePermission> perms)
    throws IOException
{
    PosixFileAttributeView view =
        getFileAttributeView(path, PosixFileAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setPermissions(perms);
    return path;
}