You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by cu...@apache.org on 2005/06/02 18:57:11 UTC
svn commit: r179609 - in /lucene/java/trunk: CHANGES.txt
src/java/org/apache/lucene/store/FSDirectory.java
Author: cutting
Date: Thu Jun 2 09:57:10 2005
New Revision: 179609
URL: http://svn.apache.org/viewcvs?rev=179609&view=rev
Log:
Fix FSDirectory.createOutput() to always create new files.
Modified:
lucene/java/trunk/CHANGES.txt
lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=179609&r1=179608&r2=179609&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Jun 2 09:57:10 2005
@@ -164,6 +164,12 @@
a given amount of milliseconds, but this didn't work.
(John Wang via Daniel Naber, Bug #33799)
+ 8. Fix FSDirectory.createOutput() to always create new files.
+ Previously, existing files were overwritten, and an index could be
+ corrupted when the old version of a file was longer than the new.
+ Now any existing file is first removed. (Doug Cutting)
+
+
Optimizations
1. Disk usage (peak requirements during indexing and optimization)
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=179609&r1=179608&r2=179609&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Thu Jun 2 09:57:10 2005
@@ -241,7 +241,7 @@
public void deleteFile(String name) throws IOException {
File file = new File(directory, name);
if (!file.delete())
- throw new IOException("Cannot delete " + name);
+ throw new IOException("Cannot delete " + file);
}
/** Renames an existing file in the directory. */
@@ -256,7 +256,7 @@
if (nu.exists())
if (!nu.delete())
- throw new IOException("Cannot delete " + to);
+ throw new IOException("Cannot delete " + nu);
// Rename the old file to the new one. Unfortunately, the renameTo()
// method does not work reliably under some JVMs. Therefore, if the
@@ -282,7 +282,7 @@
old.delete();
}
catch (IOException ioe) {
- throw new IOException("Cannot rename " + from + " to " + to);
+ throw new IOException("Cannot rename " + old + " to " + nu);
}
finally {
if (in != null) {
@@ -306,7 +306,11 @@
/** Creates a new, empty file in the directory with the given name.
Returns a stream writing this file. */
public IndexOutput createOutput(String name) throws IOException {
- return new FSIndexOutput(new File(directory, name));
+ File file = new File(directory, name);
+ if (file.exists() && !file.delete()) // delete existing, if any
+ throw new IOException("Cannot overwrite: " + file);
+
+ return new FSIndexOutput(file);
}
/** Returns a stream reading an existing file. */