mirror of https://github.com/apache/lucene.git
LUCENE-10024: remove non-existing path from history file
This commit is contained in:
parent
489ba3e4f9
commit
40038bcc92
|
@ -17,11 +17,13 @@
|
||||||
|
|
||||||
package org.apache.lucene.luke.app;
|
package org.apache.lucene.luke.app;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.lucene.index.IndexReader;
|
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.app.desktop.util.MessageUtils;
|
||||||
import org.apache.lucene.luke.models.LukeException;
|
import org.apache.lucene.luke.models.LukeException;
|
||||||
import org.apache.lucene.luke.models.util.IndexUtils;
|
import org.apache.lucene.luke.models.util.IndexUtils;
|
||||||
|
@ -74,6 +76,12 @@ public final class IndexHandler extends AbstractHandler<IndexObserver> {
|
||||||
reader = IndexUtils.openIndex(indexPath, dirImpl);
|
reader = IndexUtils.openIndex(indexPath, dirImpl);
|
||||||
} catch (NoSuchFileException e) {
|
} catch (NoSuchFileException e) {
|
||||||
log.error("Error opening index", 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(
|
throw new LukeException(
|
||||||
MessageUtils.getLocalizedMessage(
|
MessageUtils.getLocalizedMessage(
|
||||||
"openindex.message.index_path_does_not_exist", indexPath),
|
"openindex.message.index_path_does_not_exist", indexPath),
|
||||||
|
|
|
@ -28,6 +28,8 @@ public interface Preferences {
|
||||||
|
|
||||||
void addHistory(String indexPath) throws IOException;
|
void addHistory(String indexPath) throws IOException;
|
||||||
|
|
||||||
|
void removeHistory(String indexPath) throws IOException;
|
||||||
|
|
||||||
boolean isReadOnly();
|
boolean isReadOnly();
|
||||||
|
|
||||||
String getDirImpl();
|
String getDirImpl();
|
||||||
|
|
|
@ -76,6 +76,14 @@ public final class PreferencesImpl implements Preferences {
|
||||||
saveHistory();
|
saveHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeHistory(String indexPath) throws IOException {
|
||||||
|
if (history.contains(indexPath)) {
|
||||||
|
history.remove(indexPath);
|
||||||
|
saveHistory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void saveHistory() throws IOException {
|
private void saveHistory() throws IOException {
|
||||||
Files.write(historyFile(), history);
|
Files.write(historyFile(), history);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue