Skip to content

Commit a03217b

Browse files
ahornaceVladimir Kotal
authored andcommitted
Improve suggester temporary files handling (#2295)
1 parent 8182cfb commit a03217b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
import java.io.FileOutputStream;
4747
import java.io.IOException;
4848
import java.nio.charset.StandardCharsets;
49-
import java.nio.file.Files;
5049
import java.nio.file.Path;
50+
import java.nio.file.Paths;
5151
import java.util.Collection;
5252
import java.util.Collections;
5353
import java.util.HashMap;
@@ -66,11 +66,13 @@
6666
*/
6767
class SuggesterProjectData implements Closeable {
6868

69+
private static final String TMP_DIR_PROPERTY = "java.io.tmpdir";
70+
6971
private static final Logger logger = Logger.getLogger(SuggesterProjectData.class.getName());
7072

7173
private static final int MAX_TERM_SIZE = Short.MAX_VALUE - 3;
7274

73-
private static final String TEMP_DIR_PREFIX = "opengrok_suggester";
75+
private static final String WFST_TEMP_FILE_PREFIX = "opengrok_suggester_wfst";
7476

7577
private static final String WFST_FILE_SUFFIX = ".wfst";
7678

@@ -98,7 +100,7 @@ class SuggesterProjectData implements Closeable {
98100

99101
private Set<String> fields;
100102

101-
private final Path tempDir;
103+
private final Directory tempDir;
102104

103105
SuggesterProjectData(
104106
final Directory indexDir,
@@ -110,7 +112,7 @@ class SuggesterProjectData implements Closeable {
110112
this.suggesterDir = suggesterDir;
111113
this.allowMostPopular = allowMostPopular;
112114

113-
tempDir = Files.createTempDirectory(TEMP_DIR_PREFIX);
115+
tempDir = FSDirectory.open(Paths.get(System.getProperty(TMP_DIR_PROPERTY)));
114116

115117
initFields(fields);
116118
}
@@ -210,8 +212,8 @@ private WFSTCompletionLookup loadStoredWFST(final File file) throws IOException
210212
}
211213
}
212214

213-
private WFSTCompletionLookup createWFST() throws IOException {
214-
return new WFSTCompletionLookup(FSDirectory.open(tempDir), TEMP_DIR_PREFIX);
215+
private WFSTCompletionLookup createWFST() {
216+
return new WFSTCompletionLookup(tempDir, WFST_TEMP_FILE_PREFIX);
215217
}
216218

217219
private File getWFSTFile(final String field) {
@@ -451,7 +453,7 @@ public void close() throws IOException {
451453
});
452454
indexDir.close();
453455

454-
FileUtils.deleteDirectory(tempDir.toFile());
456+
tempDir.close();
455457
} finally {
456458
lock.writeLock().unlock();
457459
}

0 commit comments

Comments
 (0)