Search in sources :

Example 11 with PosixFileAttributeView

use of java.nio.file.attribute.PosixFileAttributeView in project alluxio by Alluxio.

the class FileUtils method changeLocalFileGroup.

/**
   * Changes the local file's group.
   *
   * @param path that will change owner
   * @param group the new group
   * @throws IOException if the group is unable to be changed
   */
public static void changeLocalFileGroup(String path, String group) throws IOException {
    UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
    PosixFileAttributeView view = Files.getFileAttributeView(Paths.get(path), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
    GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group);
    view.setGroup(groupPrincipal);
}
Also used : UserPrincipalLookupService(java.nio.file.attribute.UserPrincipalLookupService) GroupPrincipal(java.nio.file.attribute.GroupPrincipal) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Example 12 with PosixFileAttributeView

use of java.nio.file.attribute.PosixFileAttributeView in project jdk8u_jdk by JetBrains.

the class Files method setPosixFilePermissions.

/**
     * 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;
}
Also used : PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Example 13 with PosixFileAttributeView

use of java.nio.file.attribute.PosixFileAttributeView in project ignite by apache.

the class IgfsLocalSecondaryFileSystemTestAdapter method permissions.

/**
 * {@inheritDoc}
 */
@Override
public String permissions(String path) throws IOException {
    Path p = path(path);
    PosixFileAttributeView attrView = Files.getFileAttributeView(p, PosixFileAttributeView.class);
    if (attrView == null)
        throw new UnsupportedOperationException("Posix file attributes not available");
    int perm = 0;
    for (PosixFilePermission pfp : attrView.readAttributes().permissions()) perm |= (1 << 8 - pfp.ordinal());
    return '0' + Integer.toOctalString(perm);
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Aggregations

PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)13 Path (java.nio.file.Path)5 UserPrincipalLookupService (java.nio.file.attribute.UserPrincipalLookupService)4 GroupPrincipal (java.nio.file.attribute.GroupPrincipal)3 IOException (java.io.IOException)2 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)2 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)2 UserPrincipal (java.nio.file.attribute.UserPrincipal)2 MultiMap (com.intellij.util.containers.MultiMap)1 ChannelHandler (io.netty.channel.ChannelHandler)1 FileSystemException (io.vertx.core.file.FileSystemException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IgfsException (org.apache.ignite.igfs.IgfsException)1 IndexOutput (org.apache.lucene.store.IndexOutput)1 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)1 UserException (org.elasticsearch.cli.UserException)1 NotNull (org.jetbrains.annotations.NotNull)1