From e0df92220f3ce1e488bf7c19eba493efd5677592 Mon Sep 17 00:00:00 2001 From: Tharik Kanaka Date: Tue, 17 Mar 2020 03:59:52 +0530 Subject: [PATCH] Fix user home null issue in windows --- .../ballerinalang/command/util/OSUtils.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/ballerinalang/command/util/OSUtils.java b/src/main/java/org/ballerinalang/command/util/OSUtils.java index 587ae341..7ff48faa 100644 --- a/src/main/java/org/ballerinalang/command/util/OSUtils.java +++ b/src/main/java/org/ballerinalang/command/util/OSUtils.java @@ -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; }