You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2021/07/17 05:33:26 UTC
[lucene] branch main updated: LUCENE-10024: remove non-existing
path from history file
This is an automated email from the ASF dual-hosted git repository.
tomoko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new 40038bc LUCENE-10024: remove non-existing path from history file
40038bc is described below
commit 40038bcc92e05810775872b0aad10566129bc980
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Sat Jul 17 14:30:27 2021 +0900
LUCENE-10024: remove non-existing path from history file
---
lucene/luke/src/java/org/apache/lucene/luke/app/IndexHandler.java | 8 ++++++++
.../src/java/org/apache/lucene/luke/app/desktop/Preferences.java | 2 ++
.../java/org/apache/lucene/luke/app/desktop/PreferencesImpl.java | 8 ++++++++
3 files changed, 18 insertions(+)
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/IndexHandler.java b/lucene/luke/src/java/org/apache/lucene/luke/app/IndexHandler.java
index 4f1ee8f..46e2e3d 100644
--- a/lucene/luke/src/java/org/apache/lucene/luke/app/IndexHandler.java
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/IndexHandler.java
@@ -17,11 +17,13 @@
package org.apache.lucene.luke.app;
+import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.NoSuchFileException;
import java.util.Objects;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.luke.app.desktop.PreferencesFactory;
import org.apache.lucene.luke.app.desktop.util.MessageUtils;
import org.apache.lucene.luke.models.LukeException;
import org.apache.lucene.luke.models.util.IndexUtils;
@@ -74,6 +76,12 @@ public final class IndexHandler extends AbstractHandler<IndexObserver> {
reader = IndexUtils.openIndex(indexPath, dirImpl);
} catch (NoSuchFileException e) {
log.error("Error opening index", e);
+ try {
+ // remove the non-existing index path from history.
+ PreferencesFactory.getInstance().removeHistory(indexPath);
+ } catch (IOException ioe) {
+ log.error("Preference file is deleted?", ioe);
+ }
throw new LukeException(
MessageUtils.getLocalizedMessage(
"openindex.message.index_path_does_not_exist", indexPath),
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/Preferences.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/Preferences.java
index 982e4d8..0ead39d 100644
--- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/Preferences.java
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/Preferences.java
@@ -28,6 +28,8 @@ public interface Preferences {
void addHistory(String indexPath) throws IOException;
+ void removeHistory(String indexPath) throws IOException;
+
boolean isReadOnly();
String getDirImpl();
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/PreferencesImpl.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/PreferencesImpl.java
index 4f94c7b..b8f67b6 100644
--- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/PreferencesImpl.java
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/PreferencesImpl.java
@@ -76,6 +76,14 @@ public final class PreferencesImpl implements Preferences {
saveHistory();
}
+ @Override
+ public void removeHistory(String indexPath) throws IOException {
+ if (history.contains(indexPath)) {
+ history.remove(indexPath);
+ saveHistory();
+ }
+ }
+
private void saveHistory() throws IOException {
Files.write(historyFile(), history);
}