This is an automated email from the ASF dual-hosted git repository.

nicoloboschi pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.11 by this push:
     new b68f162634c [fix][cli] Pulsar shell: fix using directory '?' in the 
docker image (#17185)
b68f162634c is described below

commit b68f162634c8f0039012cbc817fe5a9e50468fc8
Author: Nicolò Boschi <[email protected]>
AuthorDate: Mon Aug 22 12:03:57 2022 +0200

    [fix][cli] Pulsar shell: fix using directory '?' in the docker image 
(#17185)
    
    (cherry picked from commit 21730e9f77fbd02c132636ddc32e2664e19da6aa)
---
 .../main/java/org/apache/pulsar/shell/PulsarShell.java | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java
index d8c0ee61878..e92f5a12ca0 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java
@@ -62,7 +62,6 @@ public class PulsarShell {
     private static final String EXIT_MESSAGE = "Goodbye!";
     private static final String PROPERTY_PULSAR_SHELL_DIR = 
"shellHistoryDirectory";
     private static final String PROPERTY_PERSIST_HISTORY_ENABLED = 
"shellHistoryPersistEnabled";
-    private static final String PROPERTY_PERSIST_HISTORY_PATH = 
"shellHistoryPersistPath";
     private static final String CHECKMARK = new 
String(Character.toChars(0x2714));
     private static final String XMARK = new String(Character.toChars(0x2716));
     private static final AttributedStyle LOG_STYLE = AttributedStyle.DEFAULT
@@ -87,6 +86,8 @@ public class PulsarShell {
             }
     };
 
+    private static final String DEFAULT_PULSAR_SHELL_ROOT_DIRECTORY = 
computeDefaultPulsarShellRootDirectory();
+
     interface Substitutor {
         String replace(String str, Map<String, String> vars);
     }
@@ -185,12 +186,25 @@ public class PulsarShell {
     private static File computePulsarShellFile() {
         String dir = System.getProperty(PROPERTY_PULSAR_SHELL_DIR, null);
         if (dir == null) {
-            return Paths.get(System.getProperty("user.home"), 
".pulsar-shell").toFile();
+            return Paths.get(DEFAULT_PULSAR_SHELL_ROOT_DIRECTORY, 
".pulsar-shell").toFile();
         } else {
             return new File(dir);
         }
     }
 
+    /**
+     * Compute the default Pulsar shell root directory.
+     * If system property "user.home" returns invalid value, the default value 
will be the current directory.
+     * @return
+     */
+    private static String computeDefaultPulsarShellRootDirectory() {
+        final String userHome = System.getProperty("user.home");
+        if (!StringUtils.isBlank(userHome) && !"?".equals(userHome)) {
+            return userHome;
+        }
+        return System.getProperty("user.dir");
+    }
+
     public static void main(String[] args) throws Exception {
         new PulsarShell(args).run();
     }

Reply via email to