From 4cee88c43846ea3236814636259fae43c8d63de7 Mon Sep 17 00:00:00 2001 From: Otis Gospodnetic Date: Fri, 21 Jun 2002 14:57:46 +0000 Subject: [PATCH] - Added the ability to disable creation of locks on the file system, in order to allow Lucene to be used on read-only media. To disable lock creation set 'disableLocks' system property to 'true'. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149782 13f79535-47bb-0310-9956-ffa450edef68 --- TODO.txt | 6 ++---- .../org/apache/lucene/store/FSDirectory.java | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/TODO.txt b/TODO.txt index aa5dd7da65c..21911189299 100644 --- a/TODO.txt +++ b/TODO.txt @@ -32,10 +32,8 @@ $Revision$ http://nagoya.apache.org/eyebrowse/ReadMsg?listName=lucene-dev@jakarta.apache.org&msgId=114749 http://nagoya.apache.org/eyebrowse/ReadMsg?listName=lucene-dev@jakarta.apache.org&msgId=114757 -- Add to FSDirectory the ability to specify where lock files live and - to disable the use of lock files altogether (for read-only media). - c.f. - http://nagoya.apache.org/eyebrowse/BrowseList?listName=lucene-user@jakarta.apache.org&by=thread&from=57011 +- Add to FSDirectory the ability to disable the use of lock files altogether (for read-only media). + Status: COMPLETED - Add some requested methods: String[] Document.getValues(String fieldName); diff --git a/src/java/org/apache/lucene/store/FSDirectory.java b/src/java/org/apache/lucene/store/FSDirectory.java index e06a854380b..c604dc4383f 100644 --- a/src/java/org/apache/lucene/store/FSDirectory.java +++ b/src/java/org/apache/lucene/store/FSDirectory.java @@ -77,6 +77,8 @@ final public class FSDirectory extends Directory { * require Java 1.2. Instead we use refcounts... */ private static final Hashtable DIRECTORIES = new Hashtable(); + private static final boolean DISABLE_LOCKS = Boolean.getBoolean("disableLocks"); + /** Returns the directory instance for the named location. * *

Directories are cached, so that, for a given canonical path, the same @@ -211,18 +213,31 @@ final public class FSDirectory extends Directory { return new FSInputStream(new File(directory, name)); } - /** Construct a {@link Lock}. + /** + * Constructs a {@link Lock} with the specified name. + * If JDK 1.1 is used the lock file is not really made. + * If system property disableLocks has the value of 'true' + * the lock will not be created. Assigning this property any other value + * will not prevent creation of locks. + *
+ * This is useful for using Lucene on read-only medium, such as CD-ROM. + * * @param name the name of the lock file + * @return an instance of Lock holding the lock */ public final Lock makeLock(String name) { final File lockFile = new File(directory, name); return new Lock() { public boolean obtain() throws IOException { - if (Constants.JAVA_1_1) return true; // locks disabled in jdk 1.1 + if (Constants.JAVA_1_1) + return true; // locks disabled in jdk 1.1 + if (DISABLE_LOCKS) + return true; return lockFile.createNewFile(); } public void release() { - if (Constants.JAVA_1_1) return; // locks disabled in jdk 1.1 + if (Constants.JAVA_1_1) + return; // locks disabled in jdk 1.1 lockFile.delete(); } public String toString() {