Rebuilt for db.x86-5.3
[git/cygwin-packages/libgda5.0.git] / 5.1.2-sqlite3-locking.patch
1 --- origsrc/libgda-5.1.2/libgda/sqlite/sqlite-src/sqlite3.c 2013-01-18 14:04:34.000000000 -0600
2 +++ src/libgda-5.1.2/libgda/sqlite/sqlite-src/sqlite3.c 2013-08-08 12:05:29.091211100 -0500
3 @@ -22689,6 +22689,9 @@ SQLITE_PRIVATE const char *sqlite3Opcode
4 # else
5 # include <sys/file.h>
6 # include <sys/param.h>
7 +# if defined(__CYGWIN__)
8 +# include <sys/statfs.h>
9 +# endif
10 # endif
11 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
12
13 @@ -27365,6 +27367,38 @@ typedef const sqlite3_io_methods *(*find
14 ** sqlite3_vfs object.
15 */
16
17 +#if defined(__CYGWIN__)
18 +/*
19 +** Returns the Cygwin locking strategy to use for this program instance.
20 +**
21 +** Select POSIX fcntl() advisory locking by setting an environment
22 +** variable, CYGWIN_SQLITE_LOCKING=posix. We check this only once,
23 +** then keep the same strategy until the program ends. This mode is
24 +** best for programs ported to Cygwin which assume this lock style.
25 +**
26 +** If the variable is any other value or unset, we use BSD flock()
27 +** locking instead. With Cygwin 1.7.20+, we also enable its mandatory
28 +** locking feature, which allows Cygwin SQLite to interoperate with
29 +** native Windows builds of SQLite, since those assume mandatory
30 +** Windows locks.
31 +*/
32 +typedef enum {
33 + cls_UNKNOWN,
34 + cls_POSIXAdvisory,
35 + cls_BSDMandatory,
36 +} cygwinLockingStrategyT;
37 +static cygwinLockingStrategyT cygwinLockingStrategy() {
38 + static cygwinLockingStrategyT rc = cls_UNKNOWN;
39 + if (rc == cls_UNKNOWN) {
40 + const char* strategy = getenv("CYGWIN_SQLITE_LOCKING");
41 + rc = strategy && sqlite3_stricmp(strategy, "posix") == 0 ?
42 + cls_POSIXAdvisory : cls_BSDMandatory;
43 + }
44 + assert(rc != cls_UNKNOWN);
45 + return rc;
46 +}
47 +#endif
48 +
49 /*
50 ** Initialize the contents of the unixFile structure pointed to by pId.
51 */
52 @@ -27419,6 +27453,16 @@ static int fillInUnixFile(
53 if( ctrlFlags & UNIXFILE_NOLOCK ){
54 pLockingStyle = &nolockIoMethods;
55 }else{
56 +#if __CYGWIN__ && SQLITE_ENABLE_LOCKING_STYLE
57 + if (cygwinLockingStrategy() == cls_BSDMandatory) {
58 + /* We're on Cygwin with BSD locking enabled, and user hasn't
59 + ** set the environement variable that forces us to use POSIX
60 + ** locks, so override the VFS search logic; force BSD locking.
61 + */
62 + pLockingStyle = &flockIoMethods;
63 + }
64 + else
65 +#endif
66 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
67 #if SQLITE_ENABLE_LOCKING_STYLE
68 /* Cache zFilename in the locking context (AFP and dotlock override) for
69 @@ -27941,6 +27985,43 @@ static int unixOpen(
70 p->pUnused->flags = flags;
71 }
72
73 +#ifdef __CYGWIN__
74 + cygwinLockingStrategyT cls = cygwinLockingStrategy();
75 + if (cls == cls_BSDMandatory) {
76 + /* Enable Windows mandatory locking on this FD. This allows us
77 + ** to build SQLite in "Unix mode" (SQLITE_OS_UNIX) but get the
78 + ** same locking semantics as you'd get via winLockFile() when
79 + ** building SQLite on Cygwin without setting SQLITE_OS_UNIX.
80 + **
81 + ** Turn this off with CYGWIN_SQLITE_LOCKING=posix if you want
82 + ** POSIX advisory locking instead. You want to do that when
83 + ** your program using Cygwin SQLite only needs to cooperate for
84 + ** access to a DB file with other programs also built against
85 + ** Cygwin. In that case, your programs are probably coming
86 + ** from a POSIXy system, so they will expect advisory locking
87 + ** semantics; Windows locking may confuse them.
88 + **
89 + ** We default to Windows locking semantics so we interoperate
90 + ** with native Windows programs that also use SQLite on the DB
91 + ** file we have open. e.g. Attempting to use Cygwin svn on a
92 + ** directory visible in Windows explorer with the Tortoise SVN
93 + ** extension installed. When (!) both try to open the DB, the
94 + ** Cygwin program is likely to get a file I/O error because an
95 + ** advisory lock fails on a file open with a mandatory lock.
96 + **
97 + ** Don't be confused by Cygwin's design choice to enable this
98 + ** mode for BSD locks via an fcntl() call. That POSIX locks
99 + ** are also implemented in terms of fcntl() is irrelevant.
100 + */
101 + if ((fcntl(fd, F_LCK_MANDATORY, 1) != 0) && (errno != EINVAL)) {
102 + // The API exists but it refused to enable mandatory locking!
103 + ((unixFile*)pFile)->lastErrno = errno;
104 + robust_close(p, fd, __LINE__);
105 + return SQLITE_IOERR_ACCESS;
106 + }
107 + }
108 +#endif
109 +
110 if( isDelete ){
111 #if OS_VXWORKS
112 zPath = zName;
113 @@ -27957,7 +28038,9 @@ static int unixOpen(
114 noLock = eType!=SQLITE_OPEN_MAIN_DB;
115
116
117 -#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
118 +#if (defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE)
119 + /* Don't do this for Cygwin because even though the DB could be on a FAT
120 + filesystem, its struct statfs doesn't have this field to query. */
121 if( fstatfs(fd, &fsInfo) == -1 ){
122 ((unixFile*)pFile)->lastErrno = errno;
123 robust_close(p, fd, __LINE__);
124 @@ -27975,7 +28058,8 @@ static int unixOpen(
125 if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC;
126 if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
127
128 -#if SQLITE_ENABLE_LOCKING_STYLE
129 +#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__)
130 + /* Cygwin never does proxy locking; it may be Mac OS X only? */
131 #if SQLITE_PREFER_PROXY_LOCKING
132 isAutoProxy = 1;
133 #endif
134 @@ -33870,7 +33954,7 @@ static int winFullPathname(
135 */
136 char zOut[MAX_PATH+1];
137 memset(zOut, 0, MAX_PATH+1);
138 - cygwin_conv_to_win32_path(zRelative, zOut); /* POSIX to Win32 */
139 + cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut, MAX_PATH+1);
140 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s\\%s",
141 sqlite3_data_directory, zOut);
142 }else{
143 @@ -33879,7 +33963,7 @@ static int winFullPathname(
144 ** for the buffer passed to cygwin_conv_to_full_win32_path
145 ** is MAX_PATH.
146 */
147 - cygwin_conv_to_full_win32_path(zRelative, zFull);
148 + cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull);
149 }
150 return SQLITE_OK;
151 #endif
152 --- origsrc/libgda-5.1.2/providers/sqlcipher/sqlite3.c 2013-03-16 10:44:03.000000000 -0500
153 +++ src/libgda-5.1.2/providers/sqlcipher/sqlite3.c 2013-08-08 12:05:14.853396700 -0500
154 @@ -9381,6 +9381,7 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefa
155 #endif
156
157 #if SQLITE_OS_WIN
158 +# define WIN32_LEAN_AND_MEAN
159 # include <windows.h>
160 #endif
161
162 @@ -25003,6 +25004,9 @@ SQLITE_PRIVATE const char *sqlite3Opcode
163 # else
164 # include <sys/file.h>
165 # include <sys/param.h>
166 +# if defined(__CYGWIN__)
167 +# include <sys/statfs.h>
168 +# endif
169 # endif
170 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
171
172 @@ -29679,6 +29682,38 @@ typedef const sqlite3_io_methods *(*find
173 ** sqlite3_vfs object.
174 */
175
176 +#if defined(__CYGWIN__)
177 +/*
178 +** Returns the Cygwin locking strategy to use for this program instance.
179 +**
180 +** Select POSIX fcntl() advisory locking by setting an environment
181 +** variable, CYGWIN_SQLITE_LOCKING=posix. We check this only once,
182 +** then keep the same strategy until the program ends. This mode is
183 +** best for programs ported to Cygwin which assume this lock style.
184 +**
185 +** If the variable is any other value or unset, we use BSD flock()
186 +** locking instead. With Cygwin 1.7.20+, we also enable its mandatory
187 +** locking feature, which allows Cygwin SQLite to interoperate with
188 +** native Windows builds of SQLite, since those assume mandatory
189 +** Windows locks.
190 +*/
191 +typedef enum {
192 + cls_UNKNOWN,
193 + cls_POSIXAdvisory,
194 + cls_BSDMandatory,
195 +} cygwinLockingStrategyT;
196 +static cygwinLockingStrategyT cygwinLockingStrategy() {
197 + static cygwinLockingStrategyT rc = cls_UNKNOWN;
198 + if (rc == cls_UNKNOWN) {
199 + const char* strategy = getenv("CYGWIN_SQLITE_LOCKING");
200 + rc = strategy && sqlite3_stricmp(strategy, "posix") == 0 ?
201 + cls_POSIXAdvisory : cls_BSDMandatory;
202 + }
203 + assert(rc != cls_UNKNOWN);
204 + return rc;
205 +}
206 +#endif
207 +
208 /*
209 ** Initialize the contents of the unixFile structure pointed to by pId.
210 */
211 @@ -29733,6 +29768,16 @@ static int fillInUnixFile(
212 if( ctrlFlags & UNIXFILE_NOLOCK ){
213 pLockingStyle = &nolockIoMethods;
214 }else{
215 +#if __CYGWIN__ && SQLITE_ENABLE_LOCKING_STYLE
216 + if (cygwinLockingStrategy() == cls_BSDMandatory) {
217 + /* We're on Cygwin with BSD locking enabled, and user hasn't
218 + ** set the environement variable that forces us to use POSIX
219 + ** locks, so override the VFS search logic; force BSD locking.
220 + */
221 + pLockingStyle = &flockIoMethods;
222 + }
223 + else
224 +#endif
225 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
226 #if SQLITE_ENABLE_LOCKING_STYLE
227 /* Cache zFilename in the locking context (AFP and dotlock override) for
228 @@ -30255,6 +30300,43 @@ static int unixOpen(
229 p->pUnused->flags = flags;
230 }
231
232 +#ifdef __CYGWIN__
233 + cygwinLockingStrategyT cls = cygwinLockingStrategy();
234 + if (cls == cls_BSDMandatory) {
235 + /* Enable Windows mandatory locking on this FD. This allows us
236 + ** to build SQLite in "Unix mode" (SQLITE_OS_UNIX) but get the
237 + ** same locking semantics as you'd get via winLockFile() when
238 + ** building SQLite on Cygwin without setting SQLITE_OS_UNIX.
239 + **
240 + ** Turn this off with CYGWIN_SQLITE_LOCKING=posix if you want
241 + ** POSIX advisory locking instead. You want to do that when
242 + ** your program using Cygwin SQLite only needs to cooperate for
243 + ** access to a DB file with other programs also built against
244 + ** Cygwin. In that case, your programs are probably coming
245 + ** from a POSIXy system, so they will expect advisory locking
246 + ** semantics; Windows locking may confuse them.
247 + **
248 + ** We default to Windows locking semantics so we interoperate
249 + ** with native Windows programs that also use SQLite on the DB
250 + ** file we have open. e.g. Attempting to use Cygwin svn on a
251 + ** directory visible in Windows explorer with the Tortoise SVN
252 + ** extension installed. When (!) both try to open the DB, the
253 + ** Cygwin program is likely to get a file I/O error because an
254 + ** advisory lock fails on a file open with a mandatory lock.
255 + **
256 + ** Don't be confused by Cygwin's design choice to enable this
257 + ** mode for BSD locks via an fcntl() call. That POSIX locks
258 + ** are also implemented in terms of fcntl() is irrelevant.
259 + */
260 + if ((fcntl(fd, F_LCK_MANDATORY, 1) != 0) && (errno != EINVAL)) {
261 + // The API exists but it refused to enable mandatory locking!
262 + ((unixFile*)pFile)->lastErrno = errno;
263 + robust_close(p, fd, __LINE__);
264 + return SQLITE_IOERR_ACCESS;
265 + }
266 + }
267 +#endif
268 +
269 if( isDelete ){
270 #if OS_VXWORKS
271 zPath = zName;
272 @@ -30271,7 +30353,9 @@ static int unixOpen(
273 noLock = eType!=SQLITE_OPEN_MAIN_DB;
274
275
276 -#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
277 +#if (defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE)
278 + /* Don't do this for Cygwin because even though the DB could be on a FAT
279 + filesystem, its struct statfs doesn't have this field to query. */
280 if( fstatfs(fd, &fsInfo) == -1 ){
281 ((unixFile*)pFile)->lastErrno = errno;
282 robust_close(p, fd, __LINE__);
283 @@ -30289,7 +30373,8 @@ static int unixOpen(
284 if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC;
285 if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
286
287 -#if SQLITE_ENABLE_LOCKING_STYLE
288 +#if SQLITE_ENABLE_LOCKING_STYLE && !defined(__CYGWIN__)
289 + /* Cygwin never does proxy locking; it may be Mac OS X only? */
290 #if SQLITE_PREFER_PROXY_LOCKING
291 isAutoProxy = 1;
292 #endif
293 @@ -36184,7 +36269,7 @@ static int winFullPathname(
294 */
295 char zOut[MAX_PATH+1];
296 memset(zOut, 0, MAX_PATH+1);
297 - cygwin_conv_to_win32_path(zRelative, zOut); /* POSIX to Win32 */
298 + cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut, MAX_PATH+1);
299 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s\\%s",
300 sqlite3_data_directory, zOut);
301 }else{
302 @@ -36193,7 +36278,7 @@ static int winFullPathname(
303 ** for the buffer passed to cygwin_conv_to_full_win32_path
304 ** is MAX_PATH.
305 */
306 - cygwin_conv_to_full_win32_path(zRelative, zFull);
307 + cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull);
308 }
309 return SQLITE_OK;
310 #endif
This page took 0.052423 seconds and 5 git commands to generate.