Attachment 'FixXapianOnWindows.patch'
Download 1 # HG changeset patch
2 # User Don Reid <dreid@computroix.com>
3 # Date 1204526279 25200
4 # Node ID 61d49e431a45e2334832f225550dec6420d17442
5 # Parent e9be21dd06a042cd380d7b6b7b2d4c0bc73109df
6 Allow Xapian to run under Windows
7
8 diff -r e9be21dd06a0 -r 61d49e431a45 MoinMoin/search/builtin.py
9 --- a/MoinMoin/search/builtin.py Sun Mar 02 15:35:32 2008 +0100
10 +++ b/MoinMoin/search/builtin.py Sun Mar 02 23:37:59 2008 -0700
11 @@ -11,6 +11,9 @@
12 """
13
14 import time, os, errno, codecs, logging
15 +import sys
16 +if sys.platform == 'win32':
17 + import win32file, win32con, pywintypes
18
19 from MoinMoin import wikiutil, config
20 from MoinMoin.Page import Page
21 @@ -201,7 +204,34 @@
22
23 def touch(self):
24 """ Touch the index """
25 - os.utime(self.dir, None)
26 + if sys.platform == 'win32':
27 + access=win32file.GENERIC_WRITE
28 + share=win32file.FILE_SHARE_DELETE | \
29 + win32file.FILE_SHARE_READ | \
30 + win32file.FILE_SHARE_WRITE
31 + create=win32file.OPEN_EXISTING
32 + mtime = time.gmtime()
33 + try:
34 + handle=win32file.CreateFile(self.dir,
35 + access,
36 + share,
37 + None,
38 + create,
39 + win32file.FILE_ATTRIBUTE_NORMAL |
40 + win32con.FILE_FLAG_BACKUP_SEMANTICS,
41 + None)
42 + except pywintypes.error:
43 + raise error, 'open("%s") for touch failed' % self.dir
44 + try:
45 + newTime = pywintypes.Time(mtime)
46 + win32file.SetFileTime(handle,
47 + newTime,
48 + newTime,
49 + newTime)
50 + finally:
51 + win32file.CloseHandle(handle)
52 + else:
53 + os.utime(self.dir, None)
54
55 def _search(self, query):
56 """ Actually perfom the search (read-lock acquired)
57 diff -r e9be21dd06a0 -r 61d49e431a45 MoinMoin/support/xapwrap/index.py
58 --- a/MoinMoin/support/xapwrap/index.py Sun Mar 02 15:35:32 2008 +0100
59 +++ b/MoinMoin/support/xapwrap/index.py Sun Mar 02 23:37:59 2008 -0700
60 @@ -126,74 +126,108 @@
61 try:
62 from atop.tpython import FilesystemLock
63 except ImportError:
64 - from os import symlink, readlink, remove as rmlink
65 - import errno
66 + try:
67 + from os import symlink, readlink, remove as rmlink
68 + except ImportError:
69 + import win32event
70
71 - class FilesystemLock:
72 - """A mutex.
73 + class FilesystemLock:
74 + """A mutex
75
76 - This relies on the filesystem property that creating
77 - a symlink is an atomic operation and that it will
78 - fail if the symlink already exists. Deleting the
79 - symlink will release the lock.
80 + A real mutex this time. See the non-win32 version for details.
81 + """
82
83 - @ivar name: The name of the file associated with this lock.
84 - @ivar clean: Indicates whether this lock was released cleanly by its
85 - last owner. Only meaningful after C{lock} has been called and returns
86 - True.
87 - """
88 + locked = False
89 + clean = True
90
91 - clean = None
92 - locked = False
93 + def __init__(self, name):
94 + #Mutex name cannot contain backslash
95 + name = name.replace('\\', '/')
96 + self.name = name
97 + self._mutex = win32event.CreateMutex(None, False, name)
98 + if not self._mutex:
99 + raise RuntimeError("Failed to create a named mutex")
100 +
101 + def lock(self):
102 + res = win32event.WaitForSingleObject(self._mutex, 0)
103 + self.locked = (res != win32event.WAIT_TIMEOUT)
104 + return self.locked
105 +
106 + def unlock(self):
107 + #C API ReleaseMutex version is supposed to return something to
108 + #tell whether the lock was correctly released or not. The binding
109 + #does not.
110 + win32event.ReleaseMutex(self._mutex)
111 + self.locked = False
112
113 - def __init__(self, name):
114 - self.name = name
115 + else:
116 + import errno
117
118 - def lock(self):
119 - """Acquire this lock.
120 + class FilesystemLock:
121 + """A mutex.
122
123 - @rtype: C{bool}
124 - @return: True if the lock is acquired, false otherwise.
125 + This relies on the filesystem property that creating
126 + a symlink is an atomic operation and that it will
127 + fail if the symlink already exists. Deleting the
128 + symlink will release the lock.
129 +
130 + @ivar name: The name of the file associated with this lock.
131 + @ivar clean: Indicates whether this lock was released cleanly by its
132 + last owner. Only meaningful after C{lock} has been called and returns
133 + True.
134 + """
135 +
136 + clean = None
137 + locked = False
138 +
139 + def __init__(self, name):
140 + self.name = name
141 +
142 + def lock(self):
143 + """Acquire this lock.
144 +
145 + @rtype: C{bool}
146 + @return: True if the lock is acquired, false otherwise.
147 +
148 + @raise: Any exception os.symlink() may raise, other than
149 + EEXIST.
150 + """
151 + try:
152 + pid = readlink(self.name)
153 + except (OSError, IOError), e:
154 + if e.errno != errno.ENOENT:
155 + raise
156 + self.clean = True
157 + else:
158 + if not hasattr(os, 'kill'):
159 + return False
160 + try:
161 + os.kill(int(pid), 0)
162 + except (OSError, IOError), e:
163 + if e.errno != errno.ESRCH:
164 + raise
165 + rmlink(self.name)
166 + self.clean = False
167 + else:
168 + return False
169
170 - @raise: Any exception os.symlink() may raise, other than
171 - EEXIST.
172 - """
173 - try:
174 - pid = readlink(self.name)
175 - except (OSError, IOError), e:
176 - if e.errno != errno.ENOENT:
177 - raise
178 - self.clean = True
179 - else:
180 - if not hasattr(os, 'kill'):
181 - return False
182 - try:
183 - os.kill(int(pid), 0)
184 - except (OSError, IOError), e:
185 - if e.errno != errno.ESRCH:
186 - raise
187 - rmlink(self.name)
188 - self.clean = False
189 - else:
190 - return False
191 + symlink(str(os.getpid()), self.name)
192 + self.locked = True
193 + return True
194
195 - symlink(str(os.getpid()), self.name)
196 - self.locked = True
197 - return True
198 + def unlock(self):
199 + """Release this lock.
200
201 - def unlock(self):
202 - """Release this lock.
203 + This deletes the directory with the given name.
204
205 - This deletes the directory with the given name.
206 -
207 - @raise: Any exception os.readlink() may raise, or
208 - ValueError if the lock is not owned by this process.
209 - """
210 - pid = readlink(self.name)
211 - if int(pid) != os.getpid():
212 - raise ValueError("Lock %r not owned by this process" % (self.name,))
213 - rmlink(self.name)
214 - self.locked = False
215 + @raise: Any exception os.readlink() may raise, or
216 + ValueError if the lock is not owned by this process.
217 + """
218 + pid = readlink(self.name)
219 + if int(pid) != os.getpid():
220 + raise ValueError("Lock %r not owned by this process" % (self.name,))
221 + rmlink(self.name)
222 + self.locked = False
223
224 try:
225 from twisted.python.log import msg as log
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.