Skip to content

Commit

Permalink
Merge pull request #64 from suganyasuven/version-update
Browse files Browse the repository at this point in the history
Fix the issue occurred during update new installed installation
  • Loading branch information
keizer619 authored Jan 22, 2021
2 parents 92fd356 + e215209 commit 8dd587c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/ballerinalang/command/cmd/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ String getCommandUsageInfo(String commandName) {
}

public void printVersionInfo() {
ToolUtil.getCurrentBallerinaVersion();
String output = "Update Tool " + ToolUtil.getCurrentToolsVersion() + "\n";
getPrintStream().print(output);
}
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/org/ballerinalang/command/util/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,33 @@ public static String getBallerinaVersionFilePath() throws IOException {
String userHome = getUserHome();
File ballerinaVersionfile = new File(userHome + File.separator
+ BALLERINA_HOME_DIR + File.separator + BALLERINA_CONFIG);

File installerVersionfile = new File(userHome + File.separator
+ BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION);

if (!ballerinaVersionfile.exists()) {
ballerinaVersionfile.getParentFile().mkdirs();
ballerinaVersionfile.createNewFile();
installerVersionfile.createNewFile();
ToolUtil.addExecutablePermissionToFile(ballerinaVersionfile);
ToolUtil.addExecutablePermissionToFile(installerVersionfile);
ToolUtil.setVersion(ballerinaVersionfile.getPath(), ToolUtil.getCurrentInstalledBallerinaVersion());
ToolUtil.setInstallerVersion(installerVersionfile.getPath());
}
return getUserHome() + File.separator + BALLERINA_HOME_DIR + File.separator + BALLERINA_CONFIG;
return userHome + File.separator + BALLERINA_HOME_DIR + File.separator + BALLERINA_CONFIG;
}

/**
* Provides the installer version path
*
* @return path to the file
*/
public static String getInstallerVersionFilePath() {
return getUserHome() + File.separator + BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION;
public static String getInstallerVersionFilePath() throws IOException {
String userHome = getUserHome();
File installerVersionfile = new File(userHome + File.separator
+ BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION);

if (new File(OSUtils.getInstalledInstallerVersionPath()).exists() && !installerVersionfile.exists()) {
installerVersionfile.getParentFile().mkdirs();
installerVersionfile.createNewFile();
ToolUtil.addExecutablePermissionToFile(installerVersionfile);
ToolUtil.setInstallerVersion(installerVersionfile.getPath());
ToolUtil.setVersion(getBallerinaVersionFilePath(), ToolUtil.getCurrentInstalledBallerinaVersion());
}
return userHome + File.separator + BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION;
}

public static String getBallerinaDistListFilePath() {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/ballerinalang/command/util/ToolUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ public void checkServerTrusted(java.security.cert.X509Certificate[] certs, Strin
*/
public static String getCurrentBallerinaVersion() {
try {
String userVersion = getVersion(OSUtils.getBallerinaVersionFilePath());
String installerVersion = getInstallerVersion(OSUtils.getInstalledInstallerVersionPath());
if (!installerVersion.equals(getInstallerVersion(OSUtils.getInstallerVersionFilePath()))) {
setCurrentBallerinaVersion(ToolUtil.getCurrentInstalledBallerinaVersion());
setInstallerVersion(installerVersion);
String installerVersionFilePath = OSUtils.getInstallerVersionFilePath();
if (new File(installerVersionFilePath).exists()) {
String installedInstallerVersion = getInstallerVersion(OSUtils.getInstalledInstallerVersionPath());
if (!installedInstallerVersion.equals(getInstallerVersion(installerVersionFilePath))) {
setCurrentBallerinaVersion(ToolUtil.getCurrentInstalledBallerinaVersion());
setInstallerVersion(installedInstallerVersion);
}
}
String userVersion = getVersion(OSUtils.getBallerinaVersionFilePath());
if (checkDistributionAvailable(userVersion)) {
return userVersion;
}
Expand Down

0 comments on commit 8dd587c

Please sign in to comment.