Update the thread-local storage patch, to fix #335178
[beagle.git] / beagled / Lucene.Net / upstream-changes / 02_FSDirectory-custom-locking.patch
bloba73d8d886d04832b617e29f75fb102637e7ad4ce
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 --- 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)
14 return true;
16 bool tmpBool;
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)
23 return ;
24 bool tmpBool;
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)
32 return false;
33 bool tmpBool;
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; }
44 + }
46 /// <summary>A buffer optionally used in renameTo method </summary>
47 private byte[] buffer = null;
48 @@ -158,9 +164,9 @@ namespace Lucene.Net.Store
49 /// </returns>
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.
58 ///
59 /// <p>Directories are cached, so that, for a given canonical path, the same
60 @@ -176,6 +182,70 @@ namespace Lucene.Net.Store
61 /// </returns>
62 public static FSDirectory GetDirectory(System.IO.FileInfo file, bool create)
64 + return GetDirectory(file, null, create, false);
65 + }
67 + /// <summary>Returns the directory instance for the named location.
68 + ///
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.
72 + ///
73 + /// </summary>
74 + /// <param name="path">the path to the directory.
75 + /// </param>
76 + /// <param name="tmpDir">the path to use as lock directory.
77 + /// </param>
78 + /// <param name="create">if true, create, or erase any existing contents.
79 + /// </param>
80 + /// <returns> the FSDirectory for the named file.
81 + /// </returns>
82 + public static FSDirectory GetDirectory(System.String path, System.String tmpDir, bool create)
83 + {
84 + return GetDirectory(new System.IO.FileInfo(path), tmpDir, create, false);
85 + }
87 + /// <summary>Returns the directory instance for the named location.
88 + ///
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.
92 + ///
93 + /// </summary>
94 + /// <param name="path">the path to the directory.
95 + /// </param>
96 + /// <param name="tmpDir">the path to use as lock directory.
97 + /// </param>
98 + /// <param name="create">if true, create, or erase any existing contents.
99 + /// </param>
100 + /// <param name="disable_locks">if true, disable internal locking
101 + /// </param>
102 + /// <returns> the FSDirectory for the named file.
103 + /// </returns>
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.
110 + ///
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.
114 + ///
115 + /// </summary>
116 + /// <param name="file">the path to the directory.
117 + /// </param>
118 + /// <param name="tmpDir">the path to use as lock directory.
119 + /// </param>
120 + /// <param name="create">if true, create, or erase any existing contents.
121 + /// </param>
122 + /// <param name="disable_locks">if true, disable internal locking
123 + /// </param>
124 + /// <returns> the FSDirectory for the named file.
125 + /// </returns>
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);
129 FSDirectory dir;
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;
139 else if (create)
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)
147 directory = path;
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)
157 lockDir = directory;