You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ch...@apache.org on 2011/02/22 18:23:21 UTC

svn commit: r1073421 - /karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java

Author: chirino
Date: Tue Feb 22 17:23:20 2011
New Revision: 1073421

URL: http://svn.apache.org/viewvc?rev=1073421&view=rev
Log:
Fixes KARAF-477 : Karaf console should gracefully handle errors due to the history file being read only.

Modified:
    karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java

Modified: karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java?rev=1073421&r1=1073420&r2=1073421&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java (original)
+++ karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java Tue Feb 22 17:23:20 2011
@@ -103,7 +103,38 @@ public class Console implements Runnable
 
         final File file = getHistoryFile();
         file.getParentFile().mkdirs();
-        reader.setHistory(new FileHistory(file));
+
+        // We may not have the perms to read the history file...
+        if( file.exists() && file.canRead() ) {
+            // Override the FileHistory impl to trap failures due to the
+            // user does not having write access to the history file.
+            reader.setHistory(new FileHistory(file) {
+                boolean failed = false;
+                @Override
+                public void flush() throws IOException {
+                    if( !failed ) {
+                        try {
+                            super.flush();
+                        } catch (IOException e) {
+                            failed = true;
+                            LOGGER.debug("Cold not write history file: "+file, e);
+                        }
+                    }
+                }
+
+                @Override
+                public void purge() throws IOException {
+                    if( !failed ) {
+                        try {
+                            super.purge();
+                        } catch (IOException e) {
+                            failed = true;
+                            LOGGER.debug("Cold not delete history file: "+file, e);
+                        }
+                    }
+                }
+            });
+        }
         session.put(".jline.history", reader.getHistory());
         Completer completer = createCompleter();
         if (completer != null) {