/ Check-in [d6e177fd]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to temporary file creation logic in the unix VFS.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d6e177fd09c83d46adc5b5d36e9a439aa5397450
User & Date: drh 2015-11-28 21:49:53
Context
2015-11-29
21:46
Fix the sqldiff utility program so that it works for schemas that have tables with zero-length column names. check-in: 64263ccb user: drh tags: trunk
2015-11-28
21:49
Improvements to temporary file creation logic in the unix VFS. check-in: d6e177fd user: drh tags: trunk
18:06
Add the SQLITE_FCNTL_VFS_POINTER file control which obtains a pointer to the top-level VFS in use by a database connection. check-in: 7c6a809e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  5393   5393   ** Return the name of a directory in which to put temporary files.
  5394   5394   ** If no suitable temporary file directory can be found, return NULL.
  5395   5395   */
  5396   5396   static const char *unixTempFileDir(void){
  5397   5397     static const char *azDirs[] = {
  5398   5398        0,
  5399   5399        0,
  5400         -     0,
  5401   5400        "/var/tmp",
  5402   5401        "/usr/tmp",
  5403   5402        "/tmp",
  5404         -     0        /* List terminator */
         5403  +     "."
  5405   5404     };
  5406   5405     unsigned int i;
  5407   5406     struct stat buf;
  5408         -  const char *zDir = 0;
         5407  +  const char *zDir = sqlite3_temp_directory;
  5409   5408   
  5410         -  azDirs[0] = sqlite3_temp_directory;
  5411         -  if( !azDirs[1] ) azDirs[1] = getenv("SQLITE_TMPDIR");
  5412         -  if( !azDirs[2] ) azDirs[2] = getenv("TMPDIR");
         5409  +  if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
         5410  +  if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
  5413   5411     for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
  5414   5412       if( zDir==0 ) continue;
  5415   5413       if( osStat(zDir, &buf) ) continue;
  5416   5414       if( !S_ISDIR(buf.st_mode) ) continue;
  5417   5415       if( osAccess(zDir, 07) ) continue;
  5418   5416       break;
  5419   5417     }
................................................................................
  5423   5421   /*
  5424   5422   ** Create a temporary file name in zBuf.  zBuf must be allocated
  5425   5423   ** by the calling process and must be big enough to hold at least
  5426   5424   ** pVfs->mxPathname bytes.
  5427   5425   */
  5428   5426   static int unixGetTempname(int nBuf, char *zBuf){
  5429   5427     const char *zDir;
         5428  +  int iLimit = 0;
  5430   5429   
  5431   5430     /* It's odd to simulate an io-error here, but really this is just
  5432   5431     ** using the io-error infrastructure to test that SQLite handles this
  5433   5432     ** function failing. 
  5434   5433     */
  5435   5434     SimulateIOError( return SQLITE_IOERR );
  5436   5435   
  5437   5436     zDir = unixTempFileDir();
  5438         -  if( zDir==0 ) zDir = ".";
  5439   5437     do{
  5440   5438       u64 r;
  5441   5439       sqlite3_randomness(sizeof(r), &r);
  5442   5440       assert( nBuf>2 );
  5443   5441       zBuf[nBuf-2] = 0;
  5444   5442       sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
  5445   5443                        zDir, r, 0);
  5446         -    if( zBuf[nBuf-2]!=0 ) return SQLITE_ERROR;
         5444  +    if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR;
  5447   5445     }while( osAccess(zBuf,0)==0 );
  5448   5446     return SQLITE_OK;
  5449   5447   }
  5450   5448   
  5451   5449   #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
  5452   5450   /*
  5453   5451   ** Routine to transform a unixFile into a proxy-locking unixFile.
................................................................................
  5711   5709       ** URIs with parameters.  Hence, they can always be passed into
  5712   5710       ** sqlite3_uri_parameter(). */
  5713   5711       assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
  5714   5712   
  5715   5713     }else if( !zName ){
  5716   5714       /* If zName is NULL, the upper layer is requesting a temp file. */
  5717   5715       assert(isDelete && !syncDir);
  5718         -    rc = unixGetTempname(MAX_PATHNAME+2, zTmpname);
         5716  +    rc = unixGetTempname(pVfs->mxPathname, zTmpname);
  5719   5717       if( rc!=SQLITE_OK ){
  5720   5718         return rc;
  5721   5719       }
  5722   5720       zName = zTmpname;
  5723   5721   
  5724   5722       /* Generated temporary filenames are always double-zero terminated
  5725   5723       ** for use by sqlite3_uri_parameter(). */