Skip to content

Apache Lucene open-source search software

LUCENE-4209: fix another suggester leak: dont leave behind the file when rename fails (/tmp is its own filesystem)

Robert Muir20b748a48450
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 712bf50591b..854be1980ac 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -45,7 +45,8 @@ Bug Fixes
* LUCENE-4209: Fix FSTCompletionLookup to close its sorter, so that it won't
leave temp files behind in /tmp. Fix SortedTermFreqIteratorWrapper to not
- leave temp files behind in /tmp on Windows. (Uwe Schindler, Robert Muir)
+ leave temp files behind in /tmp on Windows. Fix Sort to not leave
+ temp files behind when /tmp is a separate volume. (Uwe Schindler, Robert Muir)
Build
diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java
index 83cb1bf32c5..2f0930a0751 100644
--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java
+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java
@@ -224,10 +224,12 @@ public final class Sort {
// One partition, try to rename or copy if unsuccessful.
if (merges.size() == 1) {
+ File single = merges.get(0);
// If simple rename doesn't work this means the output is
// on a different volume or something. Copy the input then.
- if (!merges.get(0).renameTo(output)) {
- copy(merges.get(0), output);
+ if (!single.renameTo(output)) {
+ copy(single, output);
+ single.delete();
}
} else {
// otherwise merge the partitions with a priority queue.