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 04:14:46 UTC
svn commit: r1073210 -
/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
Author: chirino
Date: Tue Feb 22 03:14:46 2011
New Revision: 1073210
URL: http://svn.apache.org/viewvc?rev=1073210&view=rev
Log:
Fixes KARAF-477 : Karaf console should gracefully handle errors due to the history file being read only.
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
Modified: karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java?rev=1073210&r1=1073209&r2=1073210&view=diff
==============================================================================
--- karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java (original)
+++ karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java Tue Feb 22 03:14:46 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) {