Skip to content

Commit

Permalink
Merge pull request #49 from suganyasuven/dependency-issue
Browse files Browse the repository at this point in the history
Fix permission issue for dependencies
  • Loading branch information
keizer619 authored Oct 28, 2020
2 parents de8a329 + d888556 commit 7d13465
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/ballerinalang/command/util/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private static boolean isWindows() {
return OS.contains("win");
}

private static boolean isMac() {
public static boolean isMac() {
return OS.contains("mac");
}

Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/ballerinalang/command/util/ToolUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,12 @@ private static void downloadAndSetupDependency(HttpURLConnection conn, PrintStre
zipFile = Paths.get(zipFileLocation).toFile();
downloadFile(conn, zipFileLocation, dependency, printStream);
unzip(zipFileLocation, dependencyLocation);
addExecutablePermissionToFile(new File(dependencyLocation + File.separator + dependency
+ File.separator + "bin" + File.separator + "java"));
if(OSUtils.isMac()) {
addExecutablePermissionToDirectory(dependencyLocation + File.separator + dependency);
} else {
addExecutablePermissionToFile(new File(dependencyLocation + File.separator + dependency
+ File.separator + "bin" + File.separator + "java"));
}
if (zipFile.exists()) {
zipFile.delete();
}
Expand Down Expand Up @@ -800,4 +804,15 @@ public static String getTypeName(String version) {
return preview;
}
}

private static void addExecutablePermissionToDirectory(String filePath) {
Process process;
try {
process = Runtime.getRuntime().exec("chmod -R 755 " + filePath);
process.waitFor();
} catch (InterruptedException | IOException e) {
throw ErrorUtil.createCommandException("permission denied: you do not have write access to '" + filePath
+ "'");
}
}
}

0 comments on commit 7d13465

Please sign in to comment.