Skip to content

Commit

Permalink
Simplify the fallback case a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
chirino committed Jun 20, 2016
1 parent 40f9f23 commit 098c501
Showing 1 changed file with 1 addition and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ private void chmod755(File file) {
if (getPlatform().startsWith("windows"))
return;
// Use Files.setPosixFilePermissions if we are running Java 7+ to avoid forking the JVM for executing chmod
boolean chmodSuccessful = false;
try {
ClassLoader classLoader = getClass().getClassLoader();
// Check if the PosixFilePermissions exists in the JVM, if not this will throw a ClassNotFoundException
Expand All @@ -334,15 +333,7 @@ private void chmod755(File file) {
Class<?> filesClass = classLoader.loadClass("java.nio.file.Files");
Method setPosixFilePermissionsMethod = filesClass.getMethod("setPosixFilePermissions", pathClass, Set.class);
setPosixFilePermissionsMethod.invoke(null, new Object[] {path, permissionSet});
chmodSuccessful = true;
} catch (ClassNotFoundException ignored) {
// Ignored as we are probably running in a JVM < 7
} catch (Exception e) {
// NoSuchMethodException | InvocationTargetException | IllegalAccessException
System.err.println("Unable to use Files.setPosixFilePermissions: " + e.getMessage() +
", falling back to Runtime.exec");
}
if (!chmodSuccessful) {
} catch (Throwable ignored) {
// Fallback to starting a new process
try {
Runtime.getRuntime().exec(new String[]{"chmod", "755", file.getCanonicalPath()}).waitFor();
Expand Down

0 comments on commit 098c501

Please sign in to comment.