Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
udda1996 committed Jun 1, 2023
1 parent 84f1854 commit 408463b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
7 changes: 0 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ ballerinaJreVersion=1.1.0
jreVersion=11.0.18+10

# For test purpose
<<<<<<< HEAD
swan-lake-version=2201.2.0
swan-lake-spec-version=2022R3
swan-lake-latest-version=2201.5.0
swan-lake-latest-spec-version=2022R4
=======
swan-lake-version=2201.0.0
swan-lake-spec-version=2022R1
swan-lake-latest-version=2201.1.1
swan-lake-latest-spec-version=2022R2
>>>>>>> 66f74a2 (Fix test failures)
1-x-channel-version=1.2.0
1-x-channel-spec-version=2020R1
1-x-channel-latest-version=1.2.16
38 changes: 24 additions & 14 deletions src/main/java/org/ballerinalang/command/util/ToolUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@
import me.tongfei.progressbar.ProgressBarStyle;
import org.ballerinalang.command.Main;

import java.io.*;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -470,9 +479,9 @@ private static void downloadAndSetupDist(PrintStream printStream, HttpURLConnect
String distPath = getDistributionsPath();
String zipFileLocation = getDistributionsPath() + File.separator + distribution + ".zip";
downloadFile(conn, zipFileLocation, distribution, printStream);
String downloadedDistSha = calcDistSHA(zipFileLocation);
String remoteDistSha = getDistSHA(distribution);
if (downloadedDistSha.equals(remoteDistSha)) {
String downloadedDistHash = generateDistributionHash(zipFileLocation);
String remoteDistHash = getDistHash(distribution);
if (downloadedDistHash.equals(remoteDistHash)) {
unzip(zipFileLocation, distPath);
addExecutablePermissionToFile(new File(distPath + File.separator
+ ToolUtil.getType(distribution) + "-" + distribution + File.separator + "bin"
Expand Down Expand Up @@ -506,7 +515,7 @@ private static void downloadAndSetupDist(PrintStream printStream, HttpURLConnect
}
}

private static String getDistSHA(String distribution) {
private static String getDistHash(String distribution) {
HttpURLConnection conn = null;
String hash = "";
try {
Expand Down Expand Up @@ -553,16 +562,17 @@ private static String getDistSHA(String distribution) {
return hash;
}

private static String calcDistSHA(String zipFileLocation) throws NoSuchAlgorithmException, IOException {
private static String generateDistributionHash(String zipFileLocation) throws NoSuchAlgorithmException, IOException {
File zipFilePath = new File(zipFileLocation);
MessageDigest digest = MessageDigest.getInstance("SHA-1");
InputStream inputStream = new FileInputStream(zipFilePath);
int n = 0;
byte[] buffer = new byte[8192];
while (n != -1) {
n = inputStream.read(buffer);
if (n > 0) {
digest.update(buffer, 0, n);
MessageDigest digest = MessageDigest.getInstance("SHA-256");
try (InputStream inputStream = new FileInputStream(zipFilePath)) {
int n = 0;
byte[] buffer = new byte[8192];
while (n != -1) {
n = inputStream.read(buffer);
if (n > 0) {
digest.update(buffer, 0, n);
}
}
}
StringBuilder result = new StringBuilder();
Expand Down

0 comments on commit 408463b

Please sign in to comment.