mirror of https://github.com/apache/lucene.git
Fix FSDirectory.createOutput() to always create new files.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@179609 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4ade1d4606
commit
eea1c63a62
|
@ -164,6 +164,12 @@ Bug fixes
|
||||||
a given amount of milliseconds, but this didn't work.
|
a given amount of milliseconds, but this didn't work.
|
||||||
(John Wang via Daniel Naber, Bug #33799)
|
(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
|
Optimizations
|
||||||
|
|
||||||
1. Disk usage (peak requirements during indexing and optimization)
|
1. Disk usage (peak requirements during indexing and optimization)
|
||||||
|
|
|
@ -241,7 +241,7 @@ public class FSDirectory extends Directory {
|
||||||
public void deleteFile(String name) throws IOException {
|
public void deleteFile(String name) throws IOException {
|
||||||
File file = new File(directory, name);
|
File file = new File(directory, name);
|
||||||
if (!file.delete())
|
if (!file.delete())
|
||||||
throw new IOException("Cannot delete " + name);
|
throw new IOException("Cannot delete " + file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Renames an existing file in the directory. */
|
/** Renames an existing file in the directory. */
|
||||||
|
@ -256,7 +256,7 @@ public class FSDirectory extends Directory {
|
||||||
|
|
||||||
if (nu.exists())
|
if (nu.exists())
|
||||||
if (!nu.delete())
|
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()
|
// Rename the old file to the new one. Unfortunately, the renameTo()
|
||||||
// method does not work reliably under some JVMs. Therefore, if the
|
// method does not work reliably under some JVMs. Therefore, if the
|
||||||
|
@ -282,7 +282,7 @@ public class FSDirectory extends Directory {
|
||||||
old.delete();
|
old.delete();
|
||||||
}
|
}
|
||||||
catch (IOException ioe) {
|
catch (IOException ioe) {
|
||||||
throw new IOException("Cannot rename " + from + " to " + to);
|
throw new IOException("Cannot rename " + old + " to " + nu);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
|
@ -306,7 +306,11 @@ public class FSDirectory extends Directory {
|
||||||
/** Creates a new, empty file in the directory with the given name.
|
/** Creates a new, empty file in the directory with the given name.
|
||||||
Returns a stream writing this file. */
|
Returns a stream writing this file. */
|
||||||
public IndexOutput createOutput(String name) throws IOException {
|
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. */
|
/** Returns a stream reading an existing file. */
|
||||||
|
|
Loading…
Reference in New Issue