Skip to content

Commit

Permalink
Merge pull request #17 from keizer619/keizer619-patch-1
Browse files Browse the repository at this point in the history
Fix user home null issue in windows
  • Loading branch information
hevayo authored Mar 16, 2020
2 parents d1e3c89 + e0df922 commit 3f006c3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/main/java/org/ballerinalang/command/util/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,27 @@ private static boolean isSolaris() {
*/
private static String getUserHome() {
String userHome = System.getenv("HOME");
String user = System.getenv("USER");
String home = System.getProperty("user.home");
String username = System.getProperty("user.name");

if (user.equals(username)) {
userHome = System.getProperty("user.home");
if (isMac() || isWindows()) {
if (userHome == null) {
userHome = System.getProperty("user.home");
}
} else {
// Fixes centOS issue
home = "/home/";
userHome = home + user;
}
File file = new File(userHome);
if (!file.exists()) {
throw ErrorUtil.createCommandException(file + "not exists");
String user = System.getenv("USER");
String home = System.getProperty("user.home");
String username = System.getProperty("user.name");

if (user.equals(username)) {
userHome = System.getProperty("user.home");
} else {
// Fixes centOS issue
home = "/home/";
userHome = home + user;
}
File file = new File(userHome);
if (!file.exists()) {
throw ErrorUtil.createCommandException(file + "not exists");
}
}
return userHome;
}
Expand Down

0 comments on commit 3f006c3

Please sign in to comment.