Ejemplo n.º 1
0
 private static void setPosixFileAttributes(
     Path path, UserPrincipal owner, GroupPrincipal group, Set<PosixFilePermission> permissions)
     throws IOException {
   PosixFileAttributeView fileAttributeView =
       Files.getFileAttributeView(path, PosixFileAttributeView.class);
   fileAttributeView.setOwner(owner);
   fileAttributeView.setGroup(group);
   fileAttributeView.setPermissions(permissions);
 }
Ejemplo n.º 2
0
 private void setOwnership(File dir, String group, String owner) {
   try {
     Path path = dir.toPath();
     UserPrincipalLookupService lookupService =
         FileSystems.getDefault().getUserPrincipalLookupService();
     GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group);
     UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(owner);
     PosixFileAttributeView pfav =
         Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
     pfav.setGroup(groupPrincipal);
     pfav.setOwner(userPrincipal);
   } catch (Exception ex) {
     cp.appendln("Unable to set the file group and owner for\n   " + dir);
   }
 }