cvsimport
[beagle.git] / beagled / Lucene.Net / upstream-changes / 02_FSDirectory-custom-locking.patch
blob3e279e6807d53af93c23b34596ed2400bb472123
1 From: Jon Trowbridge <trow@novell.com>, Fredrik Hedberg <fhedberg@novell.com>
3 Allow custom per-directory locking behaviour to be defined at initialization
4 time.
6 Index: Store/FSDirectory.cs
7 ===================================================================
8 RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Store/FSDirectory.cs,v
9 retrieving revision 1.19.2.14
10 diff -u -3 -p -r1.19.2.14 FSDirectory.cs
11 --- Store/FSDirectory.cs 25 Sep 2006 23:00:22 -0000 1.19.2.14
12 +++ Store/FSDirectory.cs 25 Sep 2006 23:01:23 -0000
13 @@ -54,7 +54,7 @@ namespace Lucene.Net.Store
14 public override bool Obtain()
16 Log ("Trying to obtain lock " + lockFile.FullName);
17 - if (Lucene.Net.Store.FSDirectory.disableLocks)
18 + if (Lucene.Net.Store.FSDirectory.disableLocks || Enclosing_Instance.InstanceDisableLock)
19 return true;
21 bool tmpBool;
22 @@ -133,7 +133,7 @@ namespace Lucene.Net.Store
24 public override void Release()
26 - if (Lucene.Net.Store.FSDirectory.disableLocks)
27 + if (Lucene.Net.Store.FSDirectory.disableLocks || Enclosing_Instance.InstanceDisableLock)
28 return ;
29 bool tmpBool;
30 if (System.IO.File.Exists(lockFile.FullName))
31 @@ -160,7 +160,7 @@ namespace Lucene.Net.Store
33 public override bool IsLocked()
35 - if (Lucene.Net.Store.FSDirectory.disableLocks)
36 + if (Lucene.Net.Store.FSDirectory.disableLocks || Enclosing_Instance.InstanceDisableLock)
37 return false;
38 bool tmpBool;
39 if (System.IO.File.Exists(lockFile.FullName))
40 @@ -203,7 +203,13 @@ namespace Lucene.Net.Store
42 return FSDirectory.disableLocks;
46 + private bool instance_disable_lock = false;
47 + public bool InstanceDisableLock {
48 + get { return instance_disable_lock; }
49 + set { instance_disable_lock = value; }
50 + }
52 /// <summary> Directory specified by <code>Lucene.Net.lockDir</code>
53 /// or <code>java.io.tmpdir</code> system property
54 /// </summary>
55 @@ -232,7 +238,7 @@ namespace Lucene.Net.Store
56 /// </returns>
57 public static FSDirectory GetDirectory(System.String path, bool create)
59 - return GetDirectory(new System.IO.FileInfo(path), create);
60 + return GetDirectory(new System.IO.FileInfo(path), null, create, false);
63 /// <summary>Returns the directory instance for the named location.
64 @@ -250,6 +256,70 @@ namespace Lucene.Net.Store
65 /// </returns>
66 public static FSDirectory GetDirectory(System.IO.FileInfo file, bool create)
68 + return GetDirectory(file, null, create, false);
69 + }
71 + /// <summary>Returns the directory instance for the named location.
72 + ///
73 + /// <p>Directories are cached, so that, for a given canonical path, the same
74 + /// FSDirectory instance will always be returned. This permits
75 + /// synchronization on directories.
76 + ///
77 + /// </summary>
78 + /// <param name="path">the path to the directory.
79 + /// </param>
80 + /// <param name="tmpDir">the path to use as lock directory.
81 + /// </param>
82 + /// <param name="create">if true, create, or erase any existing contents.
83 + /// </param>
84 + /// <returns> the FSDirectory for the named file.
85 + /// </returns>
86 + public static FSDirectory GetDirectory(System.String path, System.String tmpDir, bool create)
87 + {
88 + return GetDirectory(new System.IO.FileInfo(path), tmpDir, create, false);
89 + }
91 + /// <summary>Returns the directory instance for the named location.
92 + ///
93 + /// <p>Directories are cached, so that, for a given canonical path, the same
94 + /// FSDirectory instance will always be returned. This permits
95 + /// synchronization on directories.
96 + ///
97 + /// </summary>
98 + /// <param name="path">the path to the directory.
99 + /// </param>
100 + /// <param name="tmpDir">the path to use as lock directory.
101 + /// </param>
102 + /// <param name="create">if true, create, or erase any existing contents.
103 + /// </param>
104 + /// <param name="disable_locks">if true, disable internal locking
105 + /// </param>
106 + /// <returns> the FSDirectory for the named file.
107 + /// </returns>
108 + public static FSDirectory GetDirectory(System.String path, System.String tmpDir, bool create, bool disable_locks)
110 + return GetDirectory(new System.IO.FileInfo(path), tmpDir, create, disable_locks);
113 + /// <summary>Returns the directory instance for the named location.
114 + ///
115 + /// <p>Directories are cached, so that, for a given canonical path, the same
116 + /// FSDirectory instance will always be returned. This permits
117 + /// synchronization on directories.
118 + ///
119 + /// </summary>
120 + /// <param name="file">the path to the directory.
121 + /// </param>
122 + /// <param name="tmpDir">the path to use as lock directory.
123 + /// </param>
124 + /// <param name="create">if true, create, or erase any existing contents.
125 + /// </param>
126 + /// <param name="disable_locks">if true, disable internal locking
127 + /// </param>
128 + /// <returns> the FSDirectory for the named file.
129 + /// </returns>
130 + public static FSDirectory GetDirectory(System.IO.FileInfo file, System.String tmpdir, bool create, bool disable_locks)
132 file = new System.IO.FileInfo(file.FullName);
133 FSDirectory dir;
134 lock (DIRECTORIES.SyncRoot)
135 @@ -265,7 +335,7 @@ namespace Lucene.Net.Store
137 throw new System.SystemException("cannot load FSDirectory class: " + e.ToString());
139 - dir.Init(file, create);
140 + dir.Init(file, tmpdir, create, disable_locks);
141 DIRECTORIES[file] = dir;
143 else if (create)
144 @@ -290,11 +360,17 @@ namespace Lucene.Net.Store
146 // permit subclassing
148 - private void Init(System.IO.FileInfo path, bool create)
149 + private void Init(System.IO.FileInfo path, System.String tmpDir, bool create, bool disable_locks)
151 directory = path;
153 - if (LOCK_DIR == null)
154 + this.instance_disable_lock = disable_locks;
157 + if (tmpDir != null)
159 + lockDir = new System.IO.FileInfo(tmpDir);
161 + else if (LOCK_DIR == null)
163 lockDir = directory;