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); } }
/** Outputs the class index table to the INDEX.LIST file of the root jar file. */ void dumpIndex(String rootjar, JarIndex index) throws IOException { File jarFile = new File(rootjar); Path jarPath = jarFile.toPath(); Path tmpPath = createTempFileInSameDirectoryAs(jarFile).toPath(); try { if (update(Files.newInputStream(jarPath), Files.newOutputStream(tmpPath), null, index)) { try { Files.move(tmpPath, jarPath, REPLACE_EXISTING); } catch (IOException e) { throw new IOException(getMsg("error.write.file"), e); } } } finally { Files.deleteIfExists(tmpPath); } }