You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/02/03 12:03:29 UTC

lucene-solr git commit: remove ensureCanWrite and pass explicit file open options (TRUNCATE_EXISTING)

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_5x 4de5f1d99 -> dc925081b


remove ensureCanWrite and pass explicit file open options (TRUNCATE_EXISTING)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/dc925081
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/dc925081
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/dc925081

Branch: refs/heads/branch_5x
Commit: dc925081bd730d8b7c2c5f1895396274b22533f4
Parents: 4de5f1d
Author: Mike McCandless <mi...@apache.org>
Authored: Wed Feb 3 06:03:53 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Wed Feb 3 06:03:53 2016 -0500

----------------------------------------------------------------------
 .../src/java/org/apache/lucene/store/FSDirectory.java   | 12 ++++--------
 .../org/apache/lucene/store/NativeUnixDirectory.java    |  1 -
 2 files changed, 4 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc925081/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
index 2e5c274..86bc0c1 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
@@ -19,11 +19,12 @@ package org.apache.lucene.store;
 
 import java.io.FilterOutputStream;
 import java.io.IOException;
+import java.nio.channels.ClosedChannelException; // javadoc @link
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
-import java.nio.channels.ClosedChannelException; // javadoc @link
+import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -220,15 +221,9 @@ public abstract class FSDirectory extends BaseDirectory {
   @Override
   public IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
-
-    ensureCanWrite(name);
     return new FSIndexOutput(name);
   }
 
-  protected void ensureCanWrite(String name) throws IOException {
-    Files.deleteIfExists(directory.resolve(name)); // delete existing, if any
-  }
-
   @Override
   public void sync(Collection<String> names) throws IOException {
     ensureOpen();
@@ -273,7 +268,8 @@ public abstract class FSDirectory extends BaseDirectory {
     static final int CHUNK_SIZE = 8192;
     
     public FSIndexOutput(String name) throws IOException {
-      super("FSIndexOutput(path=\"" + directory.resolve(name) + "\")", new FilterOutputStream(Files.newOutputStream(directory.resolve(name))) {
+      super("FSIndexOutput(path=\"" + directory.resolve(name) + "\")", new FilterOutputStream(Files.newOutputStream(directory.resolve(name),
+                                                                                                                    StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
         // This implementation ensures, that we never write more than CHUNK_SIZE bytes:
         @Override
         public void write(byte[] b, int offset, int length) throws IOException {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc925081/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java b/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
index e547fbc..25570f4 100644
--- a/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
+++ b/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
@@ -148,7 +148,6 @@ public class NativeUnixDirectory extends FSDirectory {
     if (context.context != Context.MERGE || context.mergeInfo.estimatedMergeBytes < minBytesDirect) {
       return delegate.createOutput(name, context);
     } else {
-      ensureCanWrite(name);
       return new NativeUnixIndexOutput(getDirectory().resolve(name), mergeBufferSize);
     }
   }