From: danielk1977 Date: Thu, 5 Jun 2008 11:39:11 +0000 (+0000) Subject: Modify the signatures of the sqlite3_vfs.xAccess and sqlite3_vfs.xCheckReservedLock... X-Git-Tag: version-3.6.10~989 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=861f74563d4cc0f8b4d63488790c0deea1167faa;p=thirdparty%2Fsqlite.git Modify the signatures of the sqlite3_vfs.xAccess and sqlite3_vfs.xCheckReservedLock functions. (CVS 5188) FossilOrigin-Name: 4226ac54beea1b58de8ab7b9d768d999f50438a6 --- diff --git a/manifest b/manifest index bfeeed5d43..84db379558 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\stypo\sin\sthe\srtree\sREADME\sfile.\s(CVS\s5187) -D 2008-06-04T15:09:17 +C Modify\sthe\ssignatures\sof\sthe\ssqlite3_vfs.xAccess\sand\ssqlite3_vfs.xCheckReservedLock\sfunctions.\s(CVS\s5188) +D 2008-06-05T11:39:11 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in ce92ea8dc7adfb743757794f51c10d1b0d9c55e4 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -127,22 +127,22 @@ F src/mutex.h 079fa6fe9da18ceb89e79012c010594c6672addb F src/mutex_os2.c 2911ea96955ab6cba734cc4ad903fe76f834b39e F src/mutex_unix.c 466d20378a0645fea64c3f2e2669c33b7802df56 F src/mutex_w32.c 133698096a2c4e81cd11ea6f4de7891c66f7b9f7 -F src/os.c 541ea39fbacc18483b3aa96cd0242bad2dd0f049 -F src/os.h 6e7e5d4efdc907b7a1a8cddb0cf984af01843fad +F src/os.c 0f6fd93b30be56fc1bb52955aa6da2092702edaa +F src/os.h 333a53ddaf25697577a58165e1216c6cb3ccf056 F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60 F src/os_os2.c 1578149e21c4eac42c7f230a6f40500846f8e781 -F src/os_unix.c a6b02934fdd4682db47c006cb03baac8694d8b77 -F src/os_win.c 812f9ba8cd90c8aa54914a56897fb534494576d8 -F src/pager.c d55885a30760028d3fe367df2fe7e2c884d65ff4 +F src/os_unix.c bea384cc48cc03630703fbf3afbc9ee4b5442663 +F src/os_win.c 9ac4e4e9c864b16e5dd087eed5770c960a5b1f09 +F src/pager.c 912792937cba5838c4515a7a284c9f57f56d603e F src/pager.h 71c58cd613174a91b50ed66edad6148639aa064a F src/parse.y fc4bd35c6088901f7c8daead26c6fb11c87d22e7 -F src/pragma.c c6dfbd16fff857aceb2fece8b34891a32d64b19a +F src/pragma.c 70e7c865dce85fdf9df81848af2169009a56ed08 F src/prepare.c cbc9301aba1d0fc3d05fae576f2eb667c189cb36 F src/printf.c f2d4f6c5b0ec24b643e85fe60258adad8b1f6acc F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a F src/select.c da43ce3080112aa77863e9c570c1df19a892acb8 F src/shell.c a12ea645271b7876c8f080146f48e20b00d367ec -F src/sqlite.h.in 444181949a6cc3ec4e5f322adca0998a8da16cab +F src/sqlite.h.in 0f4f33b54824cc8077c028a85a1dbd8a3df4fa73 F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3 F src/sqliteInt.h cfcb83222431108aa51565efecf3a084360ad4a6 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 @@ -153,22 +153,22 @@ F src/test2.c f0808cc643528b9620e4059ca9bda8346f526121 F src/test3.c 5705fc361dd60fe830f1934841aee509c733c6a9 F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071 F src/test5.c 3a6a5717a149d7ca2e6d14f5be72cf7555d54dc4 -F src/test6.c 1f7d1cc0d997f549d441036a1103b4422ce0b877 +F src/test6.c 6f960990194a0fb2f5d0a8c0a6789b8fa612297a F src/test7.c acec2256c7c2d279db5a8b5fa1a2a68fcc942c67 F src/test8.c bfebbeed68c86bab495256390636d39d195d3f1a F src/test9.c 4615ef08750245a2d96aaa7cbe2fb4aff2b57acc -F src/test_async.c 0d26a72361022f6f732dd1174c6615bad6e587ff +F src/test_async.c b862919c8c3b5522dd0d36b0ea4f742526b505cf F src/test_autoext.c 5e892ab84aece3f0428920bf46923f16ac83962a F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c F src/test_config.c 982bba6221b854a86427ae64e9c65b313b0f6e03 -F src/test_devsym.c 647b4dbf305343873c1a08095cc828a80ce2781d +F src/test_devsym.c 3b1ae8abee3fdf658f850571227deaef5e460f4a F src/test_func.c f4aafa10f17d52c43a64b47717265802e6e552b3 F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 F src/test_malloc.c 5c2c698355613d321f216ece25901be1040cc1fb F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071 -F src/test_onefile.c fd994d397b0e9cad103b1a6e1f76c61a90a38752 -F src/test_osinst.c acf306ba86a2963ba69dd87907fae447478a28f1 +F src/test_onefile.c f85394bf4a5342ed89e905b90a2d39340f60359d +F src/test_osinst.c a681c2a3ba2d90e64abfdbbe366777613316f8ba F src/test_schema.c e3f93725f7c5b2cff84a69dc4332040dfbc8f81a F src/test_server.c 7e579eb9bf6fbe9cc45e84e4c74d3d06d049a825 F src/test_tclvar.c e99b975614735553fa1c43503d85b0dd988c0e77 @@ -179,11 +179,11 @@ F src/update.c 2d7143b9014e955509cc4f323f9a9584fb898f34 F src/utf.c 8c94fa10efc78c2568d08d436acc59df4df7191b F src/util.c 43277088f8fea4109a640aa46731b8752c3fb4a7 F src/vacuum.c a5c289e561ed72283e97d2485491986bc7d684eb -F src/vdbe.c bad9123e8005eb5789cececd104cf1dffb529f2f +F src/vdbe.c 04fec4d3c89c409f52c885f5904a884a74f31666 F src/vdbe.h 1e3722d471739c2b213c6283b60373290e52f7ea F src/vdbeInt.h ede1a31cfa74d4718f41da491bd1d2b3abc137fc F src/vdbeapi.c 22b01ed175e4d4c613ee82cabc7a44a275641206 -F src/vdbeaux.c 7823f1db7f47cf70d86d1901e2030309e1cbfd02 +F src/vdbeaux.c 8ca1189489e4e415e39e5a3a1dd3dfa57b1294bb F src/vdbeblob.c 554736781ee273a8089c776e96bdb53e66f57ce6 F src/vdbefifo.c 1644a41c6366ff25a920df4ca675f12d3f559687 F src/vdbemem.c a39a822e6ae61c4cab4a512df4a315888b206911 @@ -353,7 +353,7 @@ F test/insert5.test 509017213328147d3acdfa2c441bfd82362dda41 F test/interrupt.test 42e7cf98646fd9cb4a3b131a93ed3c50b9e149f1 F test/intpkey.test 537669fd535f62632ca64828e435b9e54e8d677f F test/io.test 833a1746518ec3005aa7792f9bcb8f01923ff544 -F test/ioerr.test 32cff40562447bda194ba67ad601170edbaed49b +F test/ioerr.test a9dc72225498e95d08235352243e90e7a88e7b2b F test/ioerr2.test b9c9a0491a812707762a7c002876553be54d9969 F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd F test/ioerr4.test fc6eddfec2efc2f1ed217b9eae4c1c1d3516ce86 @@ -472,7 +472,7 @@ F test/tableapi.test 791f7e3891d9b70bdb43b311694bf5e9befcbc34 F test/tclsqlite.test 3dfb48f46de4353376fad835390b493ba066b4dc F test/tempdb.test b88ac8a19823cf771d742bf61eef93ef337c06b1 F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125 -F test/tester.tcl 1b88f471872326a2458ca1cc97a743582afcd1ba +F test/tester.tcl 2930673dd346a8ca69b577a0fc23cebbe3ddb5f4 F test/thread001.test 8fbd9559da0bbdc273e00318c7fd66c162020af7 F test/thread002.test 2c4ad2c386f60f6fe268cd91c769ee35b3c1fd0b F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35 @@ -591,7 +591,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c c65494ca99d1e09c246dfe37a7ca7a354af9990f -P bb445a4b1fe43d7b3e8546a6510f4e3c3ecb500b -R 02d2c307439c98b5a7fcc3ad90cd5b75 -U drh -Z 81e75dc7455d7d73d0c1a68631d1f39d +P 9ab87b7b0d0195787f1527b5be1475fb89330f08 +R f736eee5959ea7b2b1c25bb8c6d7f381 +U danielk1977 +Z 8a3aacae4ecc1da5df29c6db6f201b0d diff --git a/manifest.uuid b/manifest.uuid index 368d4798bb..1fd87c167c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9ab87b7b0d0195787f1527b5be1475fb89330f08 \ No newline at end of file +4226ac54beea1b58de8ab7b9d768d999f50438a6 \ No newline at end of file diff --git a/src/os.c b/src/os.c index 0948078bca..4abf630dd5 100644 --- a/src/os.c +++ b/src/os.c @@ -13,7 +13,7 @@ ** This file contains OS interface code that is common to all ** architectures. ** -** $Id: os.c,v 1.109 2008/05/29 02:53:00 shane Exp $ +** $Id: os.c,v 1.110 2008/06/05 11:39:11 danielk1977 Exp $ */ #define _SQLITE_OS_C_ 1 #include "sqliteInt.h" @@ -76,6 +76,7 @@ int sqlite3OsSync(sqlite3_file *id, int flags){ return id->pMethods->xSync(id, flags); } int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){ + DO_OS_MALLOC_TEST; return id->pMethods->xFileSize(id, pSize); } int sqlite3OsLock(sqlite3_file *id, int lockType){ @@ -85,11 +86,12 @@ int sqlite3OsLock(sqlite3_file *id, int lockType){ int sqlite3OsUnlock(sqlite3_file *id, int lockType){ return id->pMethods->xUnlock(id, lockType); } -int sqlite3OsCheckReservedLock(sqlite3_file *id){ - return id->pMethods->xCheckReservedLock(id); +int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){ + DO_OS_MALLOC_TEST; + return id->pMethods->xCheckReservedLock(id, pResOut); } int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ - return id->pMethods->xFileControl(id,op,pArg); + return id->pMethods->xFileControl(id, op, pArg); } int sqlite3OsSectorSize(sqlite3_file *id){ int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize; @@ -116,15 +118,14 @@ int sqlite3OsOpen( int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ return pVfs->xDelete(pVfs, zPath, dirSync); } -int sqlite3OsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ - int rc; -#ifdef SQLITE_TEST - void *pTstAlloc = sqlite3_malloc(10); - if (!pTstAlloc) return -1; - sqlite3_free(pTstAlloc); -#endif - rc = pVfs->xAccess(pVfs, zPath, flags); - return rc; +int sqlite3OsAccess( + sqlite3_vfs *pVfs, + const char *zPath, + int flags, + int *pResOut +){ + DO_OS_MALLOC_TEST; + return pVfs->xAccess(pVfs, zPath, flags, pResOut); } int sqlite3OsGetTempname(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut){ return pVfs->xGetTempname(pVfs, nBufOut, zBufOut); diff --git a/src/os.h b/src/os.h index c406b14099..c0f0e4ddf6 100644 --- a/src/os.h +++ b/src/os.h @@ -17,7 +17,7 @@ ** This header file is #include-ed by sqliteInt.h and thus ends up ** being included by every source file. ** -** $Id: os.h,v 1.101 2008/05/29 03:54:27 shane Exp $ +** $Id: os.h,v 1.102 2008/06/05 11:39:11 danielk1977 Exp $ */ #ifndef _SQLITE_OS_H_ #define _SQLITE_OS_H_ @@ -242,7 +242,7 @@ int sqlite3OsSync(sqlite3_file*, int); int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); int sqlite3OsLock(sqlite3_file*, int); int sqlite3OsUnlock(sqlite3_file*, int); -int sqlite3OsCheckReservedLock(sqlite3_file *id); +int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); int sqlite3OsFileControl(sqlite3_file*,int,void*); int sqlite3OsSectorSize(sqlite3_file *id); int sqlite3OsDeviceCharacteristics(sqlite3_file *id); @@ -252,7 +252,7 @@ int sqlite3OsDeviceCharacteristics(sqlite3_file *id); */ int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); int sqlite3OsDelete(sqlite3_vfs *, const char *, int); -int sqlite3OsAccess(sqlite3_vfs *, const char *, int); +int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut); int sqlite3OsGetTempname(sqlite3_vfs *, int, char *); int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *); #ifndef SQLITE_OMIT_LOAD_EXTENSION diff --git a/src/os_unix.c b/src/os_unix.c index 45b08d6c63..ae634b75bb 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -12,7 +12,7 @@ ** ** This file contains code that is specific to Unix systems. ** -** $Id: os_unix.c,v 1.183 2008/05/29 20:22:37 shane Exp $ +** $Id: os_unix.c,v 1.184 2008/06/05 11:39:11 danielk1977 Exp $ */ #include "sqliteInt.h" #if OS_UNIX /* This file is used on unix only */ @@ -1070,10 +1070,12 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){ ** non-zero. If the file is unlocked or holds only SHARED locks, then ** return zero. */ -static int unixCheckReservedLock(sqlite3_file *id){ +static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){ int r = 0; unixFile *pFile = (unixFile*)id; + SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); + assert( pFile ); enterMutex(); /* Because pFile->pLock is shared across threads */ @@ -1099,7 +1101,8 @@ static int unixCheckReservedLock(sqlite3_file *id){ leaveMutex(); OSTRACE3("TEST WR-LOCK %d %d\n", pFile->h, r); - return r; + *pResOut = r; + return SQLITE_OK; } /* @@ -1526,7 +1529,7 @@ static int _AFPFSSetLock( ** non-zero. If the file is unlocked or holds only SHARED locks, then ** return zero. */ -static int afpUnixCheckReservedLock(sqlite3_file *id){ +static int afpUnixCheckReservedLock(sqlite3_file *id, int *pResOut){ int r = 0; unixFile *pFile = (unixFile*)id; @@ -1554,7 +1557,8 @@ static int afpUnixCheckReservedLock(sqlite3_file *id){ } OSTRACE3("TEST WR-LOCK %d %d\n", pFile->h, r); - return r; + *pResOut = r; + return SQLITE_OK; } /* AFP-style locking following the behavior of unixLock, see the unixLock @@ -1786,21 +1790,22 @@ static int afpUnixClose(sqlite3_file *id) { */ typedef void flockLockingContext; -static int flockUnixCheckReservedLock(sqlite3_file *id){ +static int flockUnixCheckReservedLock(sqlite3_file *id, int *pResOut){ + int r = 1; unixFile *pFile = (unixFile*)id; - if (pFile->locktype == RESERVED_LOCK) { - return 1; /* already have a reserved lock */ - } else { + if (pFile->locktype != RESERVED_LOCK) { /* attempt to get the lock */ int rc = flock(pFile->h, LOCK_EX | LOCK_NB); if (!rc) { /* got the lock, unlock it */ flock(pFile->h, LOCK_UN); - return 0; /* no one has it reserved */ + r = 0; /* no one has it reserved */ } - return 1; /* someone else might have it reserved */ } + + *pResOut = r; + return SQLITE_OK; } static int flockUnixLock(sqlite3_file *id, int locktype) { @@ -1884,23 +1889,22 @@ struct dotlockLockingContext { }; -static int dotlockUnixCheckReservedLock(sqlite3_file *id) { +static int dotlockUnixCheckReservedLock(sqlite3_file *id, int *pResOut) { + int r = 1; unixFile *pFile = (unixFile*)id; dotlockLockingContext *context; context = (dotlockLockingContext*)pFile->lockingContext; - if (pFile->locktype == RESERVED_LOCK) { - return 1; /* already have a reserved lock */ - } else { + if (pFile->locktype != RESERVED_LOCK) { struct stat statBuf; - if (lstat(context->lockPath,&statBuf) == 0){ - /* file exists, someone else has the lock */ - return 1; - }else{ + if (lstat(context->lockPath,&statBuf) != 0){ /* file does not exist, we could have it if we want it */ - return 0; + r = 0; } } + + *pResOut = r; + return SQLITE_OK; } static int dotlockUnixLock(sqlite3_file *id, int locktype) { @@ -1992,8 +1996,9 @@ static int dotlockUnixClose(sqlite3_file *id) { */ typedef void nolockLockingContext; -static int nolockUnixCheckReservedLock(sqlite3_file *id) { - return 0; +static int nolockUnixCheckReservedLock(sqlite3_file *id, int *pResOut) { + *pResOut = 0; + return SQLITE_OK; } static int nolockUnixLock(sqlite3_file *id, int locktype) { @@ -2472,8 +2477,14 @@ static int unixDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ ** ** Otherwise return 0. */ -static int unixAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ +static int unixAccess( + sqlite3_vfs *pVfs, + const char *zPath, + int flags, + int *pResOut +){ int amode = 0; + SimulateIOError( return SQLITE_IOERR_ACCESS; ); switch( flags ){ case SQLITE_ACCESS_EXISTS: amode = F_OK; @@ -2488,7 +2499,8 @@ static int unixAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ default: assert(!"Invalid flags argument"); } - return (access(zPath, amode)==0); + *pResOut = (access(zPath, amode)==0); + return SQLITE_OK; } /* diff --git a/src/os_win.c b/src/os_win.c index aa0b466b58..b21f657058 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -12,7 +12,7 @@ ** ** This file contains code that is specific to windows. ** -** $Id: os_win.c,v 1.123 2008/05/29 03:54:27 shane Exp $ +** $Id: os_win.c,v 1.124 2008/06/05 11:39:11 danielk1977 Exp $ */ #include "sqliteInt.h" #if OS_WIN /* This file is used for windows only */ @@ -937,7 +937,7 @@ static int winLock(sqlite3_file *id, int locktype){ ** file by this or any other process. If such a lock is held, return ** non-zero, otherwise zero. */ -static int winCheckReservedLock(sqlite3_file *id){ +static int winCheckReservedLock(sqlite3_file *id, int *pResOut){ int rc; winFile *pFile = (winFile*)id; assert( pFile!=0 ); @@ -952,7 +952,8 @@ static int winCheckReservedLock(sqlite3_file *id){ rc = !rc; OSTRACE3("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc); } - return rc; + *pResOut = rc; + return SQLITE_OK; } /* @@ -1239,7 +1240,8 @@ static int winDelete( static int winAccess( sqlite3_vfs *pVfs, /* Not used on win32 */ const char *zFilename, /* Name of file to check */ - int flags /* Type of test to make on this file */ + int flags, /* Type of test to make on this file */ + int *pResOut /* OUT: Result */ ){ DWORD attr; int rc; @@ -1268,7 +1270,8 @@ static int winAccess( default: assert(!"Invalid flags argument"); } - return rc; + *pResOut = rc; + return SQLITE_OK; } diff --git a/src/pager.c b/src/pager.c index 44298cea16..8cba4a37fd 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.451 2008/06/04 06:45:59 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.452 2008/06/05 11:39:11 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -1684,12 +1684,12 @@ static int pager_delmaster(Pager *pPager, const char *zMaster){ zJournal = zMasterJournal; while( (zJournal-zMasterJournal)pTmpSpace; rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1); - if( rc!=SQLITE_OK || (zMaster[0] - && (res=sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS))==0 ) - ){ - zMaster = 0; - goto end_playback; + if( rc==SQLITE_OK && zMaster[0] ){ + rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res); } zMaster = 0; - if( res<0 ){ - rc = SQLITE_IOERR_NOMEM; + if( rc!=SQLITE_OK || !res ){ goto end_playback; } pPager->journalOff = 0; @@ -3155,22 +3151,28 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){ */ static int hasHotJournal(Pager *pPager){ sqlite3_vfs *pVfs = pPager->pVfs; - int rc; - if( !pPager->useJournal ) return 0; - if( !pPager->fd->pMethods ) return 0; - rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS); - if( rc<=0 ){ - return rc; - } - if( sqlite3OsCheckReservedLock(pPager->fd) ){ - return 0; - } - if( sqlite3PagerPagecount(pPager)==0 ){ - sqlite3OsDelete(pVfs, pPager->zJournal, 0); - return 0; - }else{ - return 1; + int res = 0; + if( pPager->useJournal && pPager->fd->pMethods ){ + int rc; + int exists; + int locked; + + rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &exists); + if( rc==SQLITE_OK && exists ){ + rc = sqlite3OsCheckReservedLock(pPager->fd, &locked); + } + + if( rc==SQLITE_OK && exists && !locked ){ + if( sqlite3PagerPagecount(pPager)==0 ){ + sqlite3OsDelete(pVfs, pPager->zJournal, 0); + exists = 0; + } + } + + res = (rc!=SQLITE_OK ? -1 : (exists && !locked)); } + + return res; } /* @@ -3498,25 +3500,24 @@ static int pagerSharedLock(Pager *pPager){ ** a read/write file handle. */ if( !isHot && pPager->journalOpen==0 ){ - int res = sqlite3OsAccess(pVfs,pPager->zJournal,SQLITE_ACCESS_EXISTS); - if( res==1 ){ - int fout = 0; - int f = SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_JOURNAL; - assert( !pPager->tempFile ); - rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &fout); - assert( rc!=SQLITE_OK || pPager->jfd->pMethods ); - if( fout&SQLITE_OPEN_READONLY ){ + int res; + rc = sqlite3OsAccess(pVfs,pPager->zJournal,SQLITE_ACCESS_EXISTS,&res); + if( rc==SQLITE_OK ){ + if( res ){ + int fout = 0; + int f = SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_JOURNAL; + assert( !pPager->tempFile ); + rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &fout); + assert( rc!=SQLITE_OK || pPager->jfd->pMethods ); + if( fout&SQLITE_OPEN_READONLY ){ + rc = SQLITE_BUSY; + sqlite3OsClose(pPager->jfd); + } + }else{ + /* If the journal does not exist, that means some other process + ** has already rolled it back */ rc = SQLITE_BUSY; - sqlite3OsClose(pPager->jfd); } - }else if( res==0 ){ - /* If the journal does not exist, that means some other process - ** has already rolled it back */ - rc = SQLITE_BUSY; - }else{ - /* If sqlite3OsAccess() returns a negative value, that means it - ** failed a memory allocation */ - rc = SQLITE_IOERR_NOMEM; } } if( rc!=SQLITE_OK ){ diff --git a/src/pragma.c b/src/pragma.c index 863254b11d..616c1f1f57 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.178 2008/06/04 06:45:59 danielk1977 Exp $ +** $Id: pragma.c,v 1.179 2008/06/05 11:39:11 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -666,11 +666,13 @@ void sqlite3Pragma( sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); } }else{ - if( zRight[0] - && sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE)==0 - ){ - sqlite3ErrorMsg(pParse, "not a writable directory"); - goto pragma_out; + if( zRight[0] ){ + int res; + sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); + if( res==0 ){ + sqlite3ErrorMsg(pParse, "not a writable directory"); + goto pragma_out; + } } if( TEMP_STORE==0 || (TEMP_STORE==1 && db->temp_store<=1) diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 15dec33715..610530a098 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.319 2008/05/30 15:35:31 shane Exp $ +** @(#) $Id: sqlite.h.in,v 1.320 2008/06/05 11:39:11 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -450,18 +450,20 @@ int sqlite3_exec( ** numeric value of its corresponding primary result code in ** its least significant 8 bits. */ -#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) -#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) -#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) -#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) -#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) -#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) -#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) -#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) -#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) -#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) -#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) -#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) +#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) +#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) +#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) +#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) +#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) +#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) +#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) +#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) +#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) +#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) +#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) +#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) +#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) +#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) /* ** CAPI3REF: Flags For File Open Operations {F10230} @@ -649,7 +651,7 @@ struct sqlite3_io_methods { int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); int (*xLock)(sqlite3_file*, int); int (*xUnlock)(sqlite3_file*, int); - int (*xCheckReservedLock)(sqlite3_file*); + int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); int (*xFileControl)(sqlite3_file*, int op, void *pArg); int (*xSectorSize)(sqlite3_file*); int (*xDeviceCharacteristics)(sqlite3_file*); @@ -808,7 +810,7 @@ struct sqlite3_vfs { int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, int flags, int *pOutFlags); int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); - int (*xAccess)(sqlite3_vfs*, const char *zName, int flags); + int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); int (*xGetTempname)(sqlite3_vfs*, int nOut, char *zOut); int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); diff --git a/src/test6.c b/src/test6.c index ebf513516e..46b6ea76ce 100644 --- a/src/test6.c +++ b/src/test6.c @@ -14,7 +14,7 @@ ** the effect on the database file of an OS crash or power failure. This ** is used to test the ability of SQLite to recover from those situations. ** -** $Id: test6.c,v 1.37 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: test6.c,v 1.38 2008/06/05 11:39:11 danielk1977 Exp $ */ #if SQLITE_TEST /* This file is used for testing only */ #include "sqliteInt.h" @@ -486,8 +486,8 @@ static int cfLock(sqlite3_file *pFile, int eLock){ static int cfUnlock(sqlite3_file *pFile, int eLock){ return sqlite3OsUnlock(((CrashFile *)pFile)->pRealFile, eLock); } -static int cfCheckReservedLock(sqlite3_file *pFile){ - return sqlite3OsCheckReservedLock(((CrashFile *)pFile)->pRealFile); +static int cfCheckReservedLock(sqlite3_file *pFile, int *pResOut){ + return sqlite3OsCheckReservedLock(((CrashFile *)pFile)->pRealFile, pResOut); } static int cfFileControl(sqlite3_file *pFile, int op, void *pArg){ return sqlite3OsFileControl(((CrashFile *)pFile)->pRealFile, op, pArg); @@ -580,9 +580,14 @@ static int cfDelete(sqlite3_vfs *pCfVfs, const char *zPath, int dirSync){ sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData; return pVfs->xDelete(pVfs, zPath, dirSync); } -static int cfAccess(sqlite3_vfs *pCfVfs, const char *zPath, int flags){ +static int cfAccess( + sqlite3_vfs *pCfVfs, + const char *zPath, + int flags, + int *pResOut +){ sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData; - return pVfs->xAccess(pVfs, zPath, flags); + return pVfs->xAccess(pVfs, zPath, flags, pResOut); } static int cfGetTempname(sqlite3_vfs *pCfVfs, int nBufOut, char *zBufOut){ sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData; diff --git a/src/test_async.c b/src/test_async.c index a8c7479198..a2671fe68f 100644 --- a/src/test_async.c +++ b/src/test_async.c @@ -10,7 +10,7 @@ ** ************************************************************************* ** -** $Id: test_async.c,v 1.42 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: test_async.c,v 1.43 2008/06/05 11:39:11 danielk1977 Exp $ ** ** This file contains an example implementation of an asynchronous IO ** backend for SQLite. @@ -906,7 +906,7 @@ static int asyncUnlock(sqlite3_file *pFile, int eLock){ ** This function is called when the pager layer first opens a database file ** and is checking for a hot-journal. */ -static int asyncCheckReservedLock(sqlite3_file *pFile){ +static int asyncCheckReservedLock(sqlite3_file *pFile, int *pResOut){ int ret = 0; AsyncFileLock *pIter; AsyncLock *pLock; @@ -922,7 +922,8 @@ static int asyncCheckReservedLock(sqlite3_file *pFile){ pthread_mutex_unlock(&async.lockMutex); ASYNC_TRACE(("CHECK-LOCK %d (%s)\n", ret, p->zName)); - return ret; + *pResOut = ret; + return SQLITE_OK; } /* @@ -1127,7 +1128,13 @@ static int asyncDelete(sqlite3_vfs *pAsyncVfs, const char *z, int syncDir){ ** Implementation of sqlite3OsAccess. This method holds the mutex from ** start to finish. */ -static int asyncAccess(sqlite3_vfs *pAsyncVfs, const char *zName, int flags){ +static int asyncAccess( + sqlite3_vfs *pAsyncVfs, + const char *zName, + int flags, + int *pResOut +){ + int rc; int ret; AsyncWrite *p; sqlite3_vfs *pVfs = (sqlite3_vfs *)pAsyncVfs->pAppData; @@ -1138,8 +1145,8 @@ static int asyncAccess(sqlite3_vfs *pAsyncVfs, const char *zName, int flags){ ); pthread_mutex_lock(&async.queueMutex); - ret = sqlite3OsAccess(pVfs, zName, flags); - if( flags==SQLITE_ACCESS_EXISTS ){ + rc = sqlite3OsAccess(pVfs, zName, flags, &ret); + if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){ for(p=async.pQueueFirst; p; p = p->pNext){ if( p->op==ASYNC_DELETE && 0==strcmp(p->zBuf, zName) ){ ret = 0; @@ -1156,7 +1163,8 @@ static int asyncAccess(sqlite3_vfs *pAsyncVfs, const char *zName, int flags){ , zName, ret) ); pthread_mutex_unlock(&async.queueMutex); - return ret; + *pResOut = ret; + return rc; } static int asyncGetTempname(sqlite3_vfs *pAsyncVfs, int nBufOut, char *zBufOut){ diff --git a/src/test_devsym.c b/src/test_devsym.c index 990d56befd..b68994a157 100644 --- a/src/test_devsym.c +++ b/src/test_devsym.c @@ -14,7 +14,7 @@ ** different device types (by overriding the return values of the ** xDeviceCharacteristics() and xSectorSize() methods). ** -** $Id: test_devsym.c,v 1.5 2008/05/29 02:53:00 shane Exp $ +** $Id: test_devsym.c,v 1.6 2008/06/05 11:39:11 danielk1977 Exp $ */ #if SQLITE_TEST /* This file is used for testing only */ @@ -48,7 +48,7 @@ static int devsymSync(sqlite3_file*, int flags); static int devsymFileSize(sqlite3_file*, sqlite3_int64 *pSize); static int devsymLock(sqlite3_file*, int); static int devsymUnlock(sqlite3_file*, int); -static int devsymCheckReservedLock(sqlite3_file*); +static int devsymCheckReservedLock(sqlite3_file*, int *); static int devsymFileControl(sqlite3_file*, int op, void *pArg); static int devsymSectorSize(sqlite3_file*); static int devsymDeviceCharacteristics(sqlite3_file*); @@ -58,7 +58,7 @@ static int devsymDeviceCharacteristics(sqlite3_file*); */ static int devsymOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); static int devsymDelete(sqlite3_vfs*, const char *zName, int syncDir); -static int devsymAccess(sqlite3_vfs*, const char *zName, int flags); +static int devsymAccess(sqlite3_vfs*, const char *zName, int flags, int *); static int devsymGetTempName(sqlite3_vfs*, int nOut, char *zOut); static int devsymFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut); #ifndef SQLITE_OMIT_LOAD_EXTENSION @@ -199,9 +199,9 @@ static int devsymUnlock(sqlite3_file *pFile, int eLock){ /* ** Check if another file-handle holds a RESERVED lock on an devsym-file. */ -static int devsymCheckReservedLock(sqlite3_file *pFile){ +static int devsymCheckReservedLock(sqlite3_file *pFile, int *pResOut){ devsym_file *p = (devsym_file *)pFile; - return sqlite3OsCheckReservedLock(p->pReal); + return sqlite3OsCheckReservedLock(p->pReal, pResOut); } /* @@ -255,8 +255,13 @@ static int devsymDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ ** Test for access permissions. Return true if the requested permission ** is available, or false otherwise. */ -static int devsymAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ - return sqlite3OsAccess(g.pVfs, zPath, flags); +static int devsymAccess( + sqlite3_vfs *pVfs, + const char *zPath, + int flags, + int *pResOut +){ + return sqlite3OsAccess(g.pVfs, zPath, flags, pResOut); } /* diff --git a/src/test_onefile.c b/src/test_onefile.c index 96ce7ad87e..594d1c3030 100644 --- a/src/test_onefile.c +++ b/src/test_onefile.c @@ -10,7 +10,7 @@ ** ************************************************************************* ** -** $Id: test_onefile.c,v 1.6 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: test_onefile.c,v 1.7 2008/06/05 11:39:11 danielk1977 Exp $ ** ** OVERVIEW: ** @@ -138,7 +138,7 @@ static int fsSync(sqlite3_file*, int flags); static int fsFileSize(sqlite3_file*, sqlite3_int64 *pSize); static int fsLock(sqlite3_file*, int); static int fsUnlock(sqlite3_file*, int); -static int fsCheckReservedLock(sqlite3_file*); +static int fsCheckReservedLock(sqlite3_file*, int *pResOut); static int fsFileControl(sqlite3_file*, int op, void *pArg); static int fsSectorSize(sqlite3_file*); static int fsDeviceCharacteristics(sqlite3_file*); @@ -154,7 +154,7 @@ static int tmpSync(sqlite3_file*, int flags); static int tmpFileSize(sqlite3_file*, sqlite3_int64 *pSize); static int tmpLock(sqlite3_file*, int); static int tmpUnlock(sqlite3_file*, int); -static int tmpCheckReservedLock(sqlite3_file*); +static int tmpCheckReservedLock(sqlite3_file*, int *pResOut); static int tmpFileControl(sqlite3_file*, int op, void *pArg); static int tmpSectorSize(sqlite3_file*); static int tmpDeviceCharacteristics(sqlite3_file*); @@ -164,7 +164,7 @@ static int tmpDeviceCharacteristics(sqlite3_file*); */ static int fsOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); static int fsDelete(sqlite3_vfs*, const char *zName, int syncDir); -static int fsAccess(sqlite3_vfs*, const char *zName, int flags); +static int fsAccess(sqlite3_vfs*, const char *zName, int flags, int *); static int fsGetTempname(sqlite3_vfs*, int nOut, char *zOut); static int fsFullPathname(sqlite3_vfs*, const char *zName, int nOut,char *zOut); static void *fsDlOpen(sqlite3_vfs*, const char *zFilename); @@ -338,7 +338,8 @@ static int tmpUnlock(sqlite3_file *pFile, int eLock){ /* ** Check if another file-handle holds a RESERVED lock on a tmp-file. */ -static int tmpCheckReservedLock(sqlite3_file *pFile){ +static int tmpCheckReservedLock(sqlite3_file *pFile, int *pResOut){ + *pResOut = 0; return SQLITE_OK; } @@ -545,8 +546,9 @@ static int fsUnlock(sqlite3_file *pFile, int eLock){ /* ** Check if another file-handle holds a RESERVED lock on an fs-file. */ -static int fsCheckReservedLock(sqlite3_file *pFile){ - return 0; +static int fsCheckReservedLock(sqlite3_file *pFile, int *pResOut){ + *pResOut = 0; + return SQLITE_OK; } /* @@ -700,7 +702,12 @@ static int fsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ ** Test for access permissions. Return true if the requested permission ** is available, or false otherwise. */ -static int fsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ +static int fsAccess( + sqlite3_vfs *pVfs, + const char *zPath, + int flags, + int *pResOut +){ fs_vfs_t *pFsVfs = (fs_vfs_t *)pVfs; fs_real_file *pReal; int isJournal = 0; @@ -708,7 +715,7 @@ static int fsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ if( flags!=SQLITE_ACCESS_EXISTS ){ sqlite3_vfs *pParent = ((fs_vfs_t *)pVfs)->pParent; - return pParent->xAccess(pParent, zPath, flags); + return pParent->xAccess(pParent, zPath, flags, pResOut); } assert(strlen("-journal")==8); @@ -719,8 +726,9 @@ static int fsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ pReal = pFsVfs->pFileList; for(; pReal && strncmp(pReal->zName, zPath, nName); pReal=pReal->pNext); - if( !pReal ) return 0; - return ((!isJournal||pReal->nJournal>0)?1:0); + + *pResOut = (pReal && (!isJournal || pReal->nJournal>0)); + return SQLITE_OK; } /* diff --git a/src/test_osinst.c b/src/test_osinst.c index 5966d05581..9daa52f1c1 100644 --- a/src/test_osinst.c +++ b/src/test_osinst.c @@ -14,7 +14,7 @@ ** adds instrumentation to all vfs and file methods. C and Tcl interfaces ** are provided to control the instrumentation. ** -** $Id: test_osinst.c,v 1.12 2008/05/29 20:22:37 shane Exp $ +** $Id: test_osinst.c,v 1.13 2008/06/05 11:39:11 danielk1977 Exp $ */ /* @@ -162,7 +162,7 @@ static int instSync(sqlite3_file*, int flags); static int instFileSize(sqlite3_file*, sqlite3_int64 *pSize); static int instLock(sqlite3_file*, int); static int instUnlock(sqlite3_file*, int); -static int instCheckReservedLock(sqlite3_file*); +static int instCheckReservedLock(sqlite3_file*, int *pResOut); static int instFileControl(sqlite3_file*, int op, void *pArg); static int instSectorSize(sqlite3_file*); static int instDeviceCharacteristics(sqlite3_file*); @@ -172,7 +172,7 @@ static int instDeviceCharacteristics(sqlite3_file*); */ static int instOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); static int instDelete(sqlite3_vfs*, const char *zName, int syncDir); -static int instAccess(sqlite3_vfs*, const char *zName, int flags); +static int instAccess(sqlite3_vfs*, const char *zName, int flags, int *); static int instGetTempName(sqlite3_vfs*, int nOut, char *zOut); static int instFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut); static void *instDlOpen(sqlite3_vfs*, const char *zFilename); @@ -339,8 +339,10 @@ static int instUnlock(sqlite3_file *pFile, int eLock){ /* ** Check if another file-handle holds a RESERVED lock on an inst-file. */ -static int instCheckReservedLock(sqlite3_file *pFile){ - OS_TIME_IO(OS_CHECKRESERVEDLOCK, 0, 0, p->pReal->pMethods->xCheckReservedLock(p->pReal)); +static int instCheckReservedLock(sqlite3_file *pFile, int *pResOut){ + OS_TIME_IO(OS_CHECKRESERVEDLOCK, 0, 0, + p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut) + ); } /* @@ -404,10 +406,15 @@ static int instDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ ** Test for access permissions. Return true if the requested permission ** is available, or false otherwise. */ -static int instAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ +static int instAccess( + sqlite3_vfs *pVfs, + const char *zPath, + int flags, + int *pResOut +){ binarylog_blob(pVfs, zPath, -1, 0); - OS_TIME_VFS(OS_ACCESS, zPath, 0, flags, 0, - REALVFS(pVfs)->xAccess(REALVFS(pVfs), zPath, flags) + OS_TIME_VFS(OS_ACCESS, zPath, 0, flags, *pResOut, + REALVFS(pVfs)->xAccess(REALVFS(pVfs), zPath, flags, pResOut) ); } diff --git a/src/vdbe.c b/src/vdbe.c index f2924e15df..1c2ee18ce0 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.745 2008/05/30 15:59:49 shane Exp $ +** $Id: vdbe.c,v 1.746 2008/06/05 11:39:11 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -487,6 +487,13 @@ static void registerTrace(FILE *out, int iReg, Mem *p){ #define CHECK_FOR_INTERRUPT \ if( db->u1.isInterrupted ) goto abort_due_to_interrupt; +#ifdef SQLITE_DEBUG +static int fileExists(sqlite3 *db, const char *zFile){ + int res; + int rc = sqlite3OsAccess(db->pVfs, zFile, SQLITE_ACCESS_EXISTS, &res); + return (res && rc==SQLITE_OK); +} +#endif /* ** Execute as much of a VDBE program as we can then return. @@ -555,8 +562,8 @@ int sqlite3VdbeExec( sqlite3VdbeIOTraceSql(p); #ifdef SQLITE_DEBUG sqlite3FaultBeginBenign(-1); - if( p->pc==0 && ((p->db->flags & SQLITE_VdbeListing)!=0 - || sqlite3OsAccess(db->pVfs, "vdbe_explain", SQLITE_ACCESS_EXISTS)==1 ) + if( p->pc==0 + && ((p->db->flags & SQLITE_VdbeListing) || fileExists(db, "vdbe_explain")) ){ int i; printf("VDBE Program Listing:\n"); @@ -565,7 +572,7 @@ int sqlite3VdbeExec( sqlite3VdbePrintOp(stdout, i, &p->aOp[i]); } } - if( sqlite3OsAccess(db->pVfs, "vdbe_trace", SQLITE_ACCESS_EXISTS)==1 ){ + if( fileExists(db, "vdbe_trace") ){ p->trace = stdout; } sqlite3FaultEndBenign(-1); @@ -591,7 +598,7 @@ int sqlite3VdbeExec( } if( p->trace==0 && pc==0 ){ sqlite3FaultBeginBenign(-1); - if( sqlite3OsAccess(db->pVfs, "vdbe_sqltrace", SQLITE_ACCESS_EXISTS)==1 ){ + if( fileExists(db, "vdbe_sqltrace") ){ sqlite3VdbePrintSql(p); } sqlite3FaultEndBenign(-1); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 74f6c31a48..3e6c09d4d4 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -14,7 +14,7 @@ ** to version 2.8.7, all this code was combined into the vdbe.c source file. ** But that file was getting too big so this subroutines were split out. ** -** $Id: vdbeaux.c,v 1.383 2008/05/13 13:27:34 drh Exp $ +** $Id: vdbeaux.c,v 1.384 2008/06/05 11:39:11 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -1286,6 +1286,7 @@ static int vdbeCommit(sqlite3 *db){ char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt); sqlite3_file *pMaster = 0; i64 offset = 0; + int res; /* Select a master journal file name */ do { @@ -1296,11 +1297,9 @@ static int vdbeCommit(sqlite3 *db){ if( !zMaster ){ return SQLITE_NOMEM; } - rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS); - }while( rc==1 ); - if( rc!=0 ){ - rc = SQLITE_IOERR_NOMEM; - }else{ + rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res); + }while( rc==SQLITE_OK && res ); + if( rc==SQLITE_OK ){ /* Open the master journal. */ rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| diff --git a/test/ioerr.test b/test/ioerr.test index 8def4958fb..adf679405d 100644 --- a/test/ioerr.test +++ b/test/ioerr.test @@ -15,11 +15,12 @@ # The tests in this file use special facilities that are only # available in the SQLite test fixture. # -# $Id: ioerr.test,v 1.35 2008/05/05 15:26:51 danielk1977 Exp $ +# $Id: ioerr.test,v 1.36 2008/06/05 11:39:12 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl + # If SQLITE_DEFAULT_AUTOVACUUM is set to true, then a simulated IO error # on the 8th IO operation in the SQL script below doesn't report an error. # @@ -113,6 +114,7 @@ do_ioerr_test ioerr-4 -ckrefcount true -tclprep { SELECT * FROM abc; } + # Test IO errors that may occur during a multi-file commit. # # Tests 8 and 17 are excluded when auto-vacuum is enabled for the same @@ -122,7 +124,7 @@ ifcapable attach { if {[string match [execsql {pragma auto_vacuum}] 1]} { set ex [list 4 17] } - do_ioerr_test ioerr-5 -ckrefcount true -sqlprep { + do_ioerr_test ioerr-5 -restoreprng 0 -ckrefcount true -sqlprep { ATTACH 'test2.db' AS test2; } -sqlbody { BEGIN; diff --git a/test/tester.tcl b/test/tester.tcl index bb070d4818..52784c9f8a 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -11,7 +11,7 @@ # This file implements some common TCL routines used for regression # testing the SQLite library # -# $Id: tester.tcl,v 1.124 2008/05/12 12:41:15 danielk1977 Exp $ +# $Id: tester.tcl,v 1.125 2008/06/05 11:39:12 danielk1977 Exp $ # # What for user input before continuing. This gives an opportunity @@ -595,6 +595,7 @@ proc do_ioerr_test {testname args} { set ::ioerropts(-count) 100000000 set ::ioerropts(-persist) 1 set ::ioerropts(-ckrefcount) 0 + set ::ioerropts(-restoreprng) 1 array set ::ioerropts $args # TEMPORARY: For 3.5.9, disable testing of extended result codes. There are @@ -604,7 +605,7 @@ proc do_ioerr_test {testname args} { set ::go 1 #reset_prng_state save_prng_state - for {set n $::ioerropts(-start)} {$::go} {incr n} { + for {set n $::ioerropts(-start)} {$::go && $n<200} {incr n} { set ::TN $n incr ::ioerropts(-count) -1 if {$::ioerropts(-count)<0} break @@ -613,7 +614,9 @@ proc do_ioerr_test {testname args} { if {[info exists ::ioerropts(-exclude)]} { if {[lsearch $::ioerropts(-exclude) $n]!=-1} continue } - restore_prng_state + if {$::ioerropts(-restoreprng)} { + restore_prng_state + } # Delete the files test.db and test2.db, then execute the TCL and # SQL (in that order) to prepare for the test case.