LUCENE-4190: don't delete files in the index directory unless they begin with an underscore

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1357346 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-07-04 17:46:28 +00:00
parent 1b4a1653d9
commit 458cb4e59a
5 changed files with 46 additions and 7 deletions

View File

@ -15,6 +15,11 @@ New features
create automata from a fixed collection of UTF-8 encoded BytesRef
(Dawid Weiss, Robert Muir)
Changes in Runtime Behavior
* LUCENE-4190: Don't delete files in the index directory unless they
begin with an underscore. (Mike McCandless, Robert Muir)
API Changes
* LUCENE-4138: update of morfologik (Polish morphological analyzer) to 1.5.3.

View File

@ -149,7 +149,8 @@ final class IndexFileDeleter {
for (String fileName : files) {
if (!fileName.endsWith("write.lock") && !fileName.equals(IndexFileNames.SEGMENTS_GEN)) {
if (!fileName.endsWith("write.lock") && !fileName.equals(IndexFileNames.SEGMENTS_GEN)
&& (fileName.startsWith("_") || fileName.startsWith(IndexFileNames.SEGMENTS))) {
// Add this file to refCounts with initial count 0:
getRefCount(fileName);

View File

@ -244,14 +244,27 @@ public final class SegmentInfo {
public void setFiles(Set<String> files) {
setFiles = files;
sizeInBytes = -1;
assert assertSaneFileNames();
}
public void addFiles(Collection<String> files) {
setFiles.addAll(files);
sizeInBytes = -1;
assert assertSaneFileNames();
}
public void addFile(String file) {
setFiles.add(file);
sizeInBytes = -1;
assert assertSaneFileNames();
}
// used only by assert
private boolean assertSaneFileNames() {
for (String file : setFiles) {
assert file.startsWith("_") : "invalid codec filename: " + file ;
}
return true;
}
/**

View File

@ -125,13 +125,13 @@ public class TestDoc extends LuceneTestCase {
printSegment(out, si2);
writer.close();
SegmentInfoPerCommit siMerge = merge(directory, si1, si2, "merge", false);
SegmentInfoPerCommit siMerge = merge(directory, si1, si2, "_merge", false);
printSegment(out, siMerge);
SegmentInfoPerCommit siMerge2 = merge(directory, si1, si2, "merge2", false);
SegmentInfoPerCommit siMerge2 = merge(directory, si1, si2, "_merge2", false);
printSegment(out, siMerge2);
SegmentInfoPerCommit siMerge3 = merge(directory, siMerge, siMerge2, "merge3", false);
SegmentInfoPerCommit siMerge3 = merge(directory, siMerge, siMerge2, "_merge3", false);
printSegment(out, siMerge3);
directory.close();
@ -160,13 +160,13 @@ public class TestDoc extends LuceneTestCase {
printSegment(out, si2);
writer.close();
siMerge = merge(directory, si1, si2, "merge", true);
siMerge = merge(directory, si1, si2, "_merge", true);
printSegment(out, siMerge);
siMerge2 = merge(directory, si1, si2, "merge2", true);
siMerge2 = merge(directory, si1, si2, "_merge2", true);
printSegment(out, siMerge2);
siMerge3 = merge(directory, siMerge, siMerge2, "merge3", true);
siMerge3 = merge(directory, siMerge, siMerge2, "_merge3", true);
printSegment(out, siMerge3);
directory.close();

View File

@ -45,6 +45,7 @@ import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.LockObtainFailedException;
@ -1799,4 +1800,23 @@ public class TestIndexWriter extends LuceneTestCase {
r.close();
dir.close();
}
//LUCENE-1468 -- make sure opening an IndexWriter with
// create=true does not remove non-index files
public void testOtherFiles() throws Throwable {
Directory dir = newDirectory();
try {
// Create my own random file:
IndexOutput out = dir.createOutput("myrandomfile", newIOContext(random()));
out.writeByte((byte) 42);
out.close();
new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random()))).close();
assertTrue(dir.fileExists("myrandomfile"));
} finally {
dir.close();
}
}
}