Search in sources :

Example 6 with GroupPrincipal

use of java.nio.file.attribute.GroupPrincipal in project jimfs by google.

the class PosixAttributeProvider method set.

@Override
public void set(File file, String view, String attribute, Object value, boolean create) {
    switch(attribute) {
        case "group":
            checkNotCreate(view, attribute, create);
            GroupPrincipal group = checkType(view, attribute, value, GroupPrincipal.class);
            if (!(group instanceof UserLookupService.JimfsGroupPrincipal)) {
                group = createGroupPrincipal(group.getName());
            }
            file.setAttribute("posix", "group", group);
            break;
        case "permissions":
            file.setAttribute("posix", "permissions", toPermissions(checkType(view, attribute, value, Set.class)));
            break;
        default:
    }
}
Also used : UserLookupService.createGroupPrincipal(com.google.common.jimfs.UserLookupService.createGroupPrincipal) GroupPrincipal(java.nio.file.attribute.GroupPrincipal)

Example 7 with GroupPrincipal

use of java.nio.file.attribute.GroupPrincipal 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)

Aggregations

GroupPrincipal (java.nio.file.attribute.GroupPrincipal)7 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)4 UserPrincipalLookupService (java.nio.file.attribute.UserPrincipalLookupService)4 Path (java.nio.file.Path)3 UserPrincipal (java.nio.file.attribute.UserPrincipal)3 IOException (java.io.IOException)2 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)2 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)2 Test (org.junit.Test)2 UserLookupService.createGroupPrincipal (com.google.common.jimfs.UserLookupService.createGroupPrincipal)1 FileSystemException (io.vertx.core.file.FileSystemException)1 HashSet (java.util.HashSet)1 IgfsException (org.apache.ignite.igfs.IgfsException)1