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 mi...@apache.org on 2008/11/29 13:16:56 UTC
svn commit: r721670 - in /lucene/java/trunk/src:
java/org/apache/lucene/index/SegmentInfos.java
java/org/apache/lucene/store/FSDirectory.java
test/org/apache/lucene/store/TestDirectory.java
test/org/apache/lucene/store/TestLockFactory.java
Author: mikemccand
Date: Sat Nov 29 04:16:54 2008
New Revision: 721670
URL: http://svn.apache.org/viewvc?rev=721670&view=rev
Log:
LUCENE-1464: in FSDir, don't mkdir until first createOutput is called
Modified:
lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
lucene/java/trunk/src/test/org/apache/lucene/store/TestDirectory.java
lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=721670&r1=721669&r2=721670&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Sat Nov 29 04:16:54 2008
@@ -130,8 +130,6 @@
*/
public static long getCurrentSegmentGeneration(Directory directory) throws IOException {
String[] files = directory.list();
- if (files == null)
- throw new IOException("cannot read directory " + directory + ": list() returned null");
return getCurrentSegmentGeneration(files);
}
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=721670&r1=721669&r2=721670&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 Sat Nov 29 04:16:54 2008
@@ -178,7 +178,7 @@
public static FSDirectory getDirectory(File file, LockFactory lockFactory)
throws IOException
{
- file = createCanonicalDir(file);
+ file = getCanonicalPath(file);
FSDirectory dir;
synchronized (DIRECTORIES) {
@@ -197,6 +197,7 @@
if (lockFactory != null && lockFactory != dir.getLockFactory()) {
throw new IOException("Directory was previously created with a different LockFactory instance; please pass null as the lockFactory instance and use setLockFactory to change it");
}
+ dir.checked = false;
}
}
synchronized (dir) {
@@ -256,17 +257,23 @@
}
// returns the canonical version of the directory, creating it if it doesn't exist.
- private static File createCanonicalDir(File file) throws IOException {
- file = new File(file.getCanonicalPath());
+ private static File getCanonicalPath(File file) throws IOException {
+ return new File(file.getCanonicalPath());
+ }
+
+ private boolean checked;
- if (file.exists() && !file.isDirectory())
- throw new IOException(file + " not a directory");
+ final void createDir() throws IOException {
+ if (!checked) {
+ if (directory.exists() && !directory.isDirectory())
+ throw new IOException(directory + " not a directory");
- if (!file.exists())
- if (!file.mkdirs())
- throw new IOException("Cannot create directory: " + file);
+ if (!directory.exists())
+ if (!directory.mkdirs())
+ throw new IOException("Cannot create directory: " + directory);
- return file;
+ checked = true;
+ }
}
private File directory = null;
@@ -283,7 +290,7 @@
* Use {@link #getDirectory(String)} if singletons per path are needed.
*/
public FSDirectory(File path, LockFactory lockFactory) throws IOException {
- path = createCanonicalDir(path);
+ path = getCanonicalPath(path);
init(path, lockFactory);
refCount = 1;
}
@@ -469,6 +476,7 @@
Returns a stream writing this file. */
public IndexOutput createOutput(String name) throws IOException {
ensureOpen();
+ createDir();
File file = new File(directory, name);
if (file.exists() && !file.delete()) // delete existing, if any
throw new IOException("Cannot overwrite: " + file);
Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestDirectory.java?rev=721670&r1=721669&r2=721670&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestDirectory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestDirectory.java Sat Nov 29 04:16:54 2008
@@ -18,6 +18,7 @@
*/
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
import java.io.File;
@@ -115,5 +116,17 @@
}
}
+ // LUCENE-1464
+ public void testDontCreate() throws Throwable {
+ File path = new File(System.getProperty("tempDir"), "doesnotexist");
+ try {
+ assertTrue(!path.exists());
+ Directory dir = new FSDirectory(path, null);
+ assertTrue(!path.exists());
+ dir.close();
+ } finally {
+ _TestUtil.rmDir(path);
+ }
+ }
}
Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java?rev=721670&r1=721669&r2=721670&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Sat Nov 29 04:16:54 2008
@@ -300,8 +300,8 @@
// Different lock factory instance should hit IOException:
try {
- FSDirectory fs2 = FSDirectory.getDirectory(indexDirName, new SingleInstanceLockFactory());
- fail("Should have hit an IOException because LockFactory instances differ");
+ FSDirectory.getDirectory(indexDirName, new SingleInstanceLockFactory());
+ fail("Should have hit an IOException because LockFactory instances differ");
} catch (IOException e) {
}
@@ -371,8 +371,6 @@
NativeFSLockFactory f = new NativeFSLockFactory(System.getProperty("tempDir"));
- NativeFSLockFactory f2 = new NativeFSLockFactory(System.getProperty("tempDir"));
-
f.setLockPrefix("test");
Lock l = f.makeLock("commit");
Lock l2 = f.makeLock("commit");
@@ -485,7 +483,6 @@
}
public void run() {
IndexSearcher searcher = null;
- WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer();
Query query = new TermQuery(new Term("content", "aaa"));
for(int i=0;i<this.numIteration;i++) {
try{
@@ -566,10 +563,12 @@
private void rmDir(String dirName) {
File dir = new java.io.File(dirName);
String[] files = dir.list(); // clear old files
- for (int i = 0; i < files.length; i++) {
+ if (files != null) {
+ for (int i = 0; i < files.length; i++) {
File file = new File(dir, files[i]);
file.delete();
+ }
+ dir.delete();
}
- dir.delete();
}
}