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:
}
}
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);
}
Aggregations