From: dan Date: Mon, 10 Feb 2014 21:09:39 +0000 (+0000) Subject: Fix a bug causing the POWERSAFE_OVERWRITE device-characteristic flag to be set incorr... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=35b85b4855f85cc183ee31b997304b20cf2c7dcd;p=thirdparty%2Fsqlite.git Fix a bug causing the POWERSAFE_OVERWRITE device-characteristic flag to be set incorrectly if file opening is deferred. FossilOrigin-Name: 95d0c58d2791d81b432e7d263f3fc2f26858d395 --- diff --git a/manifest b/manifest index 1b2f1a34d9..6dc2b8a4cc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\schange\sto\sos_unix.c\sto\sdelay\screating\sa\sdatabase\sfile\suntil\sit\sis\sfirst\swritten. -D 2014-02-10T19:37:03.413 +C Fix\sa\sbug\scausing\sthe\sPOWERSAFE_OVERWRITE\sdevice-characteristic\sflag\sto\sbe\sset\sincorrectly\sif\sfile\sopening\sis\sdeferred. +D 2014-02-10T21:09:39.090 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -205,7 +205,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c 1b147e4cf7cc39e618115c14a086aed44bc91ace F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 -F src/os_unix.c dcb7dd4fb2ef823b534383bb7e58efdf8cb7d582 +F src/os_unix.c a45a0d2fc8e0e78d018c4b25a705217212e990fa F src/os_win.c d4284f003445054a26689f1264b1b9bf7261bd1b F src/pager.c efa923693e958696eee69b205a20bfbc402c8480 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428 @@ -1152,10 +1152,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P a45b87713c0afca2be2ace9500513620a024c0a2 -R 116d1a6917169d2dbbd8194f87400b30 -T *branch * deferred-open -T *sym-deferred-open * -T -sym-trunk * +P 538f7b25e436682adba10a158f082de24782cf00 +R fc51d757e99a991be98333c8143d7ae1 U dan -Z 79711705a6aa2396617bcc4018494171 +Z 7f6e10654a9f0b8d3fc129f44354c867 diff --git a/manifest.uuid b/manifest.uuid index 0ecd57ff12..cb6dbc6c90 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -538f7b25e436682adba10a158f082de24782cf00 \ No newline at end of file +95d0c58d2791d81b432e7d263f3fc2f26858d395 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index b133f9878f..f043421458 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1359,7 +1359,7 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){ assert( pFile ); SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); - if( pFile->ctrlFlags==UNIXFILE_DEFERRED ){ + if( pFile->ctrlFlags & UNIXFILE_DEFERRED ){ *pResOut = 0; return SQLITE_OK; } @@ -1529,7 +1529,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){ return SQLITE_OK; } - if( pFile->ctrlFlags==UNIXFILE_DEFERRED ){ + if( pFile->ctrlFlags & UNIXFILE_DEFERRED ){ int eOrigLock = pFile->eFileLock; if( eFileLock==SHARED_LOCK ){ int statrc; @@ -1753,7 +1753,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ return SQLITE_OK; } unixEnterMutex(); - if( pFile->ctrlFlags==UNIXFILE_DEFERRED ) goto end_unlock; + if( pFile->ctrlFlags & UNIXFILE_DEFERRED ) goto end_unlock; pInode = pFile->pInode; assert( pInode->nShared!=0 ); if( pFile->eFileLock>SHARED_LOCK ){ @@ -3205,7 +3205,7 @@ static int unixRead( ); #endif - if( pFile->ctrlFlags==UNIXFILE_DEFERRED ){ + if( pFile->ctrlFlags & UNIXFILE_DEFERRED ){ int rc; struct stat sBuf; memset(&sBuf, 0, sizeof(sBuf)); @@ -3678,7 +3678,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){ int rc; struct stat buf; assert( id ); - if( pFile->ctrlFlags==UNIXFILE_DEFERRED ){ + if( pFile->ctrlFlags & UNIXFILE_DEFERRED ){ rc = osStat(pFile->zPath, &buf); if( rc && errno==ENOENT ){ rc = 0; @@ -5890,25 +5890,39 @@ static int unixOpenDeferred( | SQLITE_OPEN_CREATE; const int mask2 = SQLITE_OPEN_READONLY | SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_AUTOPROXY; - int rc = SQLITE_OK; /* Return code */ /* If all the flags in mask1 are set, and all the flags in mask2 are - ** clear, then this will be a deferred open. */ - if( zPath && (flags & (mask1 | mask2))==mask1 ){ - unixFile *p = (unixFile*)pFile; - memset(p, 0, sizeof(unixFile)); - - p->pMethod = (**(finder_type*)pVfs->pAppData)(0, 0); - p->pVfs = pVfs; - p->h = -1; - p->ctrlFlags = UNIXFILE_DEFERRED; - p->openFlags = flags; - p->zPath = zPath; - if( pOutFlags ) *pOutFlags = flags; - }else{ - rc = unixOpen(pVfs, zPath, pFile, flags, pOutFlags); + ** clear, the file does not exist but the directory does and is + ** writable, then this is a deferred open. */ + if( 0 && zPath && (flags & (mask1 | mask2))==mask1 ){ + int posixrc; + posixrc = osAccess(zPath, F_OK); + if( posixrc && errno==ENOENT ){ + char zDirname[MAX_PATHNAME+1]; + int i; + for(i=(int)strlen(zPath); i>1 && zPath[i]!='/'; i--); + memcpy(zDirname, zPath, i); + zDirname[i] = '\0'; + posixrc = osAccess(zDirname, W_OK); + if( posixrc==0 ){ + unixFile *p = (unixFile*)pFile; + memset(p, 0, sizeof(unixFile)); + p->pMethod = (**(finder_type*)pVfs->pAppData)(0, 0); + p->pVfs = pVfs; + p->h = -1; + p->ctrlFlags = UNIXFILE_DEFERRED; + if( sqlite3_uri_boolean(((flags & UNIXFILE_URI) ? zPath : 0), + "psow", SQLITE_POWERSAFE_OVERWRITE) ){ + p->ctrlFlags |= UNIXFILE_PSOW; + } + p->openFlags = flags; + p->zPath = zPath; + if( pOutFlags ) *pOutFlags = flags; + return SQLITE_OK; + } + } } - return rc; + return unixOpen(pVfs, zPath, pFile, flags, pOutFlags); } /*