Skip to content

Commit

Permalink
Merge pull request #292 from udda1996/fix-permission
Browse files Browse the repository at this point in the history
Add distribution validation before the permission check
  • Loading branch information
udda1996 authored May 3, 2023
2 parents 27ace15 + 68e4bd6 commit ae2e017
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jreVersion=11.0.18+10
# For test purpose
swan-lake-version=2201.2.0
swan-lake-spec-version=2022R3
swan-lake-latest-version=2201.4.1
swan-lake-latest-version=2201.5.0
swan-lake-latest-spec-version=2022R4
1-x-channel-version=1.2.0
1-x-channel-spec-version=2020R1
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/org/ballerinalang/command/cmd/PullCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void execute() {
if (pullCommands.size() > 1) {
throw ErrorUtil.createDistSubCommandUsageExceptionWithHelp("too many arguments", getName());
}
ToolUtil.handleInstallDirPermission();
PrintStream printStream = getPrintStream();
String distribution = pullCommands.get(0);

Expand All @@ -80,10 +79,29 @@ public void execute() {
distribution = ToolUtil.getLatest(distributions.get(0).getVersion(), "patch");
}

// To check whether the distribution is a valid one
if (!distribution.equals(ToolUtil.LATEST_PULL_INPUT)) {
boolean validDist = false;
List<Channel> channels = ToolUtil.getDistributions(printStream);
for (Channel channel : channels) {
List<Distribution> distributions = channel.getDistributions();
for (Distribution dist : distributions) {
if (dist.getVersion().equals(distribution)) {
validDist = true;
break;
}
}
}
if (!validDist) {
throw ErrorUtil.createDistributionNotFoundException(distribution);
}
}

if (distribution.equals(ToolUtil.getCurrentBallerinaVersion())) {
printStream.println("'" + distribution + "' is already the active distribution");
return;
}
ToolUtil.handleInstallDirPermission();
ToolUtil.downloadDistribution(printStream, distribution, ToolUtil.getType(distribution), distribution, testFlag);
ToolUtil.useBallerinaVersion(printStream, distribution);
printStream.println("'" + distribution + "' successfully set as the active distribution");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ballerinalang/command/util/ToolUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ public static void updateTool(PrintStream printStream) {
if (latestVersion == null) {
printStream.println("Failed to find the latest update tool version");
} else if (!latestVersion.equals(version)) {
ToolUtil.handleInstallDirPermission();
ToolUtil.downloadTool(printStream, latestVersion);
try {
executeFile(printStream);
Expand Down

0 comments on commit ae2e017

Please sign in to comment.