/ Check-in [191aef98]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Make the xAccess method of the unix VFS smaller and faster.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 191aef986ffc4ef34d813e417e52a4ec820b0300
User & Date: drh 2015-11-25 18:03:33
Context
2015-11-25
18:07
Update test_fs.c to include a virtual table that reads a file-system hierarchy. Use it to further test GLOB and LIKE support for virtual tables. check-in: 6ef6578c user: dan tags: trunk
18:03
Make the xAccess method of the unix VFS smaller and faster. check-in: 191aef98 user: drh tags: trunk
15:15
Remove unused methods from the unix VFS. check-in: 228bd15b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  5936   5936   */
  5937   5937   static int unixAccess(
  5938   5938     sqlite3_vfs *NotUsed,   /* The VFS containing this xAccess method */
  5939   5939     const char *zPath,      /* Path of the file to examine */
  5940   5940     int flags,              /* What do we want to learn about the zPath file? */
  5941   5941     int *pResOut            /* Write result boolean here */
  5942   5942   ){
  5943         -  int amode = 0;
  5944   5943     UNUSED_PARAMETER(NotUsed);
  5945   5944     SimulateIOError( return SQLITE_IOERR_ACCESS; );
  5946         -  switch( flags ){
  5947         -    case SQLITE_ACCESS_EXISTS:
  5948         -      amode = F_OK;
  5949         -      break;
  5950         -    case SQLITE_ACCESS_READWRITE:
  5951         -      amode = W_OK|R_OK;
  5952         -      break;
  5953         -    case SQLITE_ACCESS_READ:
  5954         -      amode = R_OK;
  5955         -      break;
         5945  +  assert( pResOut!=0 );
  5956   5946   
  5957         -    default:
  5958         -      assert(!"Invalid flags argument");
  5959         -  }
  5960         -  *pResOut = (osAccess(zPath, amode)==0);
  5961         -  if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
         5947  +  /* The spec says there are three possible values for flags.  But only
         5948  +  ** two of them are actually used */
         5949  +  assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
         5950  +
         5951  +  if( flags==SQLITE_ACCESS_EXISTS ){
  5962   5952       struct stat buf;
  5963         -    if( 0==osStat(zPath, &buf) && buf.st_size==0 ){
  5964         -      *pResOut = 0;
  5965         -    }
         5953  +    *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0);
         5954  +  }else{
         5955  +    *pResOut = osAccess(zPath, W_OK|R_OK)==0;
  5966   5956     }
  5967   5957     return SQLITE_OK;
  5968   5958   }
  5969   5959   
  5970   5960   
  5971   5961   /*
  5972   5962   ** Turn a relative pathname into a full pathname. The relative path
................................................................................
  6001   5991     ** zPath is copied directly into zOut. Either way, nByte is left set to
  6002   5992     ** the size of the string copied into zOut[] in bytes.  */
  6003   5993     nByte = osReadlink(zPath, zOut, nOut-1);
  6004   5994     if( nByte<0 ){
  6005   5995       if( errno!=EINVAL && errno!=ENOENT ){
  6006   5996         return unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zPath);
  6007   5997       }
  6008         -    zOut[nOut-1] = '\0';
  6009         -    sqlite3_snprintf(nOut-1, zOut, "%s", zPath);
         5998  +    sqlite3_snprintf(nOut, zOut, "%s", zPath);
  6010   5999       nByte = sqlite3Strlen30(zOut);
  6011   6000     }else{
  6012   6001       zOut[nByte] = '\0';
  6013   6002     }
  6014   6003   
  6015   6004     /* If buffer zOut[] now contains an absolute path there is nothing more
  6016   6005     ** to do. If it contains a relative path, do the following: