Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue occurred during update new installed installation #64

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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