]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a bug causing the POWERSAFE_OVERWRITE device-characteristic flag to be set incorr...
authordan <dan@noemail.net>
Mon, 10 Feb 2014 21:09:39 +0000 (21:09 +0000)
committerdan <dan@noemail.net>
Mon, 10 Feb 2014 21:09:39 +0000 (21:09 +0000)
FossilOrigin-Name: 95d0c58d2791d81b432e7d263f3fc2f26858d395

manifest
manifest.uuid
src/os_unix.c

index 1b2f1a34d933eda171ac1b3ba0b95fbfb6f070a2..6dc2b8a4ccda90d0abcd6000c9016c980608ebaf 100644 (file)
--- 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
index 0ecd57ff12a4bb58598a1c6b98f63770e007d051..cb6dbc6c908df11533026a3ce098e96028a3fe81 100644 (file)
@@ -1 +1 @@
-538f7b25e436682adba10a158f082de24782cf00
\ No newline at end of file
+95d0c58d2791d81b432e7d263f3fc2f26858d395
\ No newline at end of file
index b133f9878fbc92af6158855c0c7e1a86ff838f29..f043421458927ab11d4c44399eda817daf1e525f 100644 (file)
@@ -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);
 }
 
 /*