1 From: Jon Trowbridge <trow@novell.com>, Fredrik Hedberg <fhedberg@novell.com>
3 Allow custom per-directory locking behaviour to be defined at initialization
6 --- Lucene.Net/Store/FSDirectory.cs.orig 2005-10-02 08:54:56.000000000 +0100
7 +++ Lucene.Net/Store/FSDirectory.cs 2005-10-02 09:43:39.000000000 +0100
8 @@ -52,7 +52,7 @@ namespace Lucene.Net.Store
10 public override bool Obtain()
12 - if (Lucene.Net.Store.FSDirectory.DISABLE_LOCKS)
13 + if (Lucene.Net.Store.FSDirectory.DISABLE_LOCKS || Enclosing_Instance.DisableLocks)
17 @@ -85,7 +85,7 @@ namespace Lucene.Net.Store
19 public override void Release()
21 - if (Lucene.Net.Store.FSDirectory.DISABLE_LOCKS)
22 + if (Lucene.Net.Store.FSDirectory.DISABLE_LOCKS || Enclosing_Instance.DisableLocks)
25 if (System.IO.File.Exists(lockFile.FullName))
26 @@ -104,7 +104,7 @@ namespace Lucene.Net.Store
28 public override bool IsLocked()
30 - if (Lucene.Net.Store.FSDirectory.DISABLE_LOCKS)
31 + if (Lucene.Net.Store.FSDirectory.DISABLE_LOCKS || Enclosing_Instance.DisableLocks)
34 if (System.IO.File.Exists(lockFile.FullName))
35 @@ -139,6 +139,12 @@ namespace Lucene.Net.Store
36 private static System.Type IMPL;
38 private static System.Security.Cryptography.MD5 DIGESTER;
40 + private bool disable_locks = false;
41 + public bool DisableLocks {
42 + get { return disable_locks; }
43 + set { disable_locks = value; }
46 /// <summary>A buffer optionally used in renameTo method </summary>
47 private byte[] buffer = null;
48 @@ -158,9 +164,9 @@ namespace Lucene.Net.Store
50 public static FSDirectory GetDirectory(System.String path, bool create)
52 - return GetDirectory(new System.IO.FileInfo(path), create);
53 + return GetDirectory(new System.IO.FileInfo(path), null, create, false);
57 /// <summary>Returns the directory instance for the named location.
59 /// <p>Directories are cached, so that, for a given canonical path, the same
60 @@ -176,6 +182,70 @@ namespace Lucene.Net.Store
62 public static FSDirectory GetDirectory(System.IO.FileInfo file, bool create)
64 + return GetDirectory(file, null, create, false);
67 + /// <summary>Returns the directory instance for the named location.
69 + /// <p>Directories are cached, so that, for a given canonical path, the same
70 + /// FSDirectory instance will always be returned. This permits
71 + /// synchronization on directories.
74 + /// <param name="path">the path to the directory.
76 + /// <param name="tmpDir">the path to use as lock directory.
78 + /// <param name="create">if true, create, or erase any existing contents.
80 + /// <returns> the FSDirectory for the named file.
82 + public static FSDirectory GetDirectory(System.String path, System.String tmpDir, bool create)
84 + return GetDirectory(new System.IO.FileInfo(path), tmpDir, create, false);
87 + /// <summary>Returns the directory instance for the named location.
89 + /// <p>Directories are cached, so that, for a given canonical path, the same
90 + /// FSDirectory instance will always be returned. This permits
91 + /// synchronization on directories.
94 + /// <param name="path">the path to the directory.
96 + /// <param name="tmpDir">the path to use as lock directory.
98 + /// <param name="create">if true, create, or erase any existing contents.
100 + /// <param name="disable_locks">if true, disable internal locking
102 + /// <returns> the FSDirectory for the named file.
104 + public static FSDirectory GetDirectory(System.String path, System.String tmpDir, bool create, bool disable_locks)
106 + return GetDirectory(new System.IO.FileInfo(path), tmpDir, create, disable_locks);
109 + /// <summary>Returns the directory instance for the named location.
111 + /// <p>Directories are cached, so that, for a given canonical path, the same
112 + /// FSDirectory instance will always be returned. This permits
113 + /// synchronization on directories.
116 + /// <param name="file">the path to the directory.
118 + /// <param name="tmpDir">the path to use as lock directory.
120 + /// <param name="create">if true, create, or erase any existing contents.
122 + /// <param name="disable_locks">if true, disable internal locking
124 + /// <returns> the FSDirectory for the named file.
126 + public static FSDirectory GetDirectory(System.IO.FileInfo file, System.String tmpdir, bool create, bool disable_locks)
128 file = new System.IO.FileInfo(file.FullName);
130 lock (DIRECTORIES.SyncRoot)
131 @@ -191,7 +261,7 @@ namespace Lucene.Net.Store
133 throw new System.SystemException("cannot load FSDirectory class: " + e.ToString());
135 - dir.Init(file, create);
136 + dir.Init(file, tmpdir, create, disable_locks);
137 DIRECTORIES[file] = dir;
140 @@ -216,11 +286,16 @@ namespace Lucene.Net.Store
142 // permit subclassing
144 - private void Init(System.IO.FileInfo path, bool create)
145 + private void Init(System.IO.FileInfo path, System.String tmpDir, bool create, bool disable_locks)
148 + this.disable_locks = disable_locks;
150 - if (LOCK_DIR == null)
151 + if (tmpDir != null)
153 + lockDir = new System.IO.FileInfo(tmpDir);
155 + else if (LOCK_DIR == null)