Skip to content

Commit 9930bfa

Browse files
ahornaceVladimir Kotal
authored andcommitted
Fix stale temporary directories created by suggester
1 parent bcc804e commit 9930bfa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

suggester/src/main/java/org/opengrok/suggest/SuggesterProjectData.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SuggesterProjectData implements Closeable {
7070

7171
private static final int MAX_TERM_SIZE = Short.MAX_VALUE - 3;
7272

73-
private static final String TEMP_DIR_PREFIX = "opengrok";
73+
private static final String TEMP_DIR_PREFIX = "opengrok_suggester";
7474

7575
private static final String WFST_FILE_SUFFIX = ".wfst";
7676

@@ -98,6 +98,8 @@ class SuggesterProjectData implements Closeable {
9898

9999
private Set<String> fields;
100100

101+
private final Path tempDir;
102+
101103
SuggesterProjectData(
102104
final Directory indexDir,
103105
final Path suggesterDir,
@@ -108,6 +110,8 @@ class SuggesterProjectData implements Closeable {
108110
this.suggesterDir = suggesterDir;
109111
this.allowMostPopular = allowMostPopular;
110112

113+
tempDir = Files.createTempDirectory(TEMP_DIR_PREFIX);
114+
111115
initFields(fields);
112116
}
113117

@@ -207,7 +211,7 @@ private WFSTCompletionLookup loadStoredWFST(final File file) throws IOException
207211
}
208212

209213
private WFSTCompletionLookup createWFST() throws IOException {
210-
return new WFSTCompletionLookup(FSDirectory.open(Files.createTempDirectory(TEMP_DIR_PREFIX)), TEMP_DIR_PREFIX);
214+
return new WFSTCompletionLookup(FSDirectory.open(tempDir), TEMP_DIR_PREFIX);
211215
}
212216

213217
private File getWFSTFile(final String field) {
@@ -446,6 +450,8 @@ public void close() throws IOException {
446450
}
447451
});
448452
indexDir.close();
453+
454+
FileUtils.deleteDirectory(tempDir.toFile());
449455
} finally {
450456
lock.writeLock().unlock();
451457
}

0 commit comments

Comments
 (0)