/ Check-in [36f11acc]
Login

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

Overview
Comment:Revise logic in winDelete to check the file prior to attempting to delete it.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | av-defense
Files: files | file ages | folders
SHA1: 36f11acc531a524407e03c797a6a1bcf88bad809
User & Date: mistachkin 2011-07-12 14:02:47
Context
2011-07-12
14:38
Merge the improved anti-virus defenses into the trunk. check-in: 0207fd9b user: drh tags: trunk
14:02
Revise logic in winDelete to check the file prior to attempting to delete it. Closed-Leaf check-in: 36f11acc user: mistachkin tags: av-defense
13:51
Improvements to the logging that occurs on an antivirus I/O retry. check-in: ff0ff75c user: drh tags: av-defense
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

   422    422   */
   423    423   static int retryIoerr(int *pnRetry){
   424    424     DWORD e;
   425    425     if( *pnRetry>=SQLITE_WIN32_IOERR_RETRY ){
   426    426       return 0;
   427    427     }
   428    428     e = GetLastError();
   429         -  if( e==ERROR_LOCK_VIOLATION || e==ERROR_SHARING_VIOLATION ){
          429  +  if( e==ERROR_ACCESS_DENIED ||
          430  +      e==ERROR_LOCK_VIOLATION ||
          431  +      e==ERROR_SHARING_VIOLATION ){
   430    432       Sleep(SQLITE_WIN32_IOERR_RETRY_DELAY*(1+*pnRetry));
   431    433       ++*pnRetry;
   432    434       return 1;
   433    435     }
   434    436     return 0;
   435    437   }
   436    438   
................................................................................
  2384   2386   
  2385   2387     SimulateIOError(return SQLITE_IOERR_DELETE);
  2386   2388     zConverted = convertUtf8Filename(zFilename);
  2387   2389     if( zConverted==0 ){
  2388   2390       return SQLITE_NOMEM;
  2389   2391     }
  2390   2392     if( isNT() ){
  2391         -    while( (rc = DeleteFileW(zConverted))!=0 || retryIoerr(&cnt) ){}
         2393  +    rc = 1;
         2394  +    while( GetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         2395  +           (rc = DeleteFileW(zConverted))==0 && retryIoerr(&cnt) ){}
         2396  +    rc = rc ? SQLITE_OK : SQLITE_ERROR;
  2392   2397   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2393   2398   ** Since the ASCII version of these Windows API do not exist for WINCE,
  2394   2399   ** it's important to not reference them for WINCE builds.
  2395   2400   */
  2396   2401   #if SQLITE_OS_WINCE==0
  2397   2402     }else{
  2398         -    while( (rc = DeleteFileW(zConverted))!=0 || retryIoerr(&cnt) ){}
         2403  +    rc = 1;
         2404  +    while( GetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         2405  +           (rc = DeleteFileA(zConverted))==0 && retryIoerr(&cnt) ){}
         2406  +    rc = rc ? SQLITE_OK : SQLITE_ERROR;
  2399   2407   #endif
  2400   2408     }
  2401   2409     if( rc ){
  2402   2410       rc = winLogError(SQLITE_IOERR_DELETE, "winDelete", zFilename);
  2403   2411     }else{
  2404   2412       logIoerr(cnt);
  2405   2413     }