/ Check-in [f32dbe47]
Login

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

Overview
Comment:Changes to help SQLite cope with virus scanners and other programs that open journal files for reading and thus prevent SQLite from deleting them in order to commit a transaction. (CVS 3200)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f32dbe47ffd1e7e5695f02bf4263d80bea177ffb
User & Date: drh 2006-06-04 23:02:20
Context
2006-06-04
23:20
Fix a windows portability problem in trans.test. (CVS 3201) check-in: f2538dfd user: drh tags: trunk
23:02
Changes to help SQLite cope with virus scanners and other programs that open journal files for reading and thus prevent SQLite from deleting them in order to commit a transaction. (CVS 3200) check-in: f32dbe47 user: drh tags: trunk
2006-06-03
18:04
Remove unused variables from vdbe.c. (CVS 3199) check-in: d54750ae user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

476
477
478
479
480
481
482


483

484

485
486
487
488
489

490

491
492
493
494
495
496
497
498
499
500
501
...
634
635
636
637
638
639
640


641
642
643
644
645
646
647
648

649
650
651
652
653


654
655
656
657
658
659
660
661

662
663
664
665
666
667
668
...
795
796
797
798
799
800
801

802

803

804

805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
#endif /* OS_WINCE */

/*
** Delete the named file
*/
int sqlite3WinDelete(const char *zFilename){
  WCHAR *zWide = utf8ToUnicode(zFilename);


  if( zWide ){

    DeleteFileW(zWide);

    sqliteFree(zWide);
  }else{
#if OS_WINCE
    return SQLITE_NOMEM;
#else

    DeleteFileA(zFilename);

#endif
  }
  TRACE2("DELETE \"%s\"\n", zFilename);
  return SQLITE_OK;
}

/*
** Return TRUE if the named file exists.
*/
int sqlite3WinFileExists(const char *zFilename){
  int exists = 0;
................................................................................
  fileflags = FILE_FLAG_RANDOM_ACCESS;
#if !OS_WINCE
  if( delFlag ){
    fileflags |= FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE;
  }
#endif
  if( zWide ){


    h = CreateFileW(zWide,
       GENERIC_READ | GENERIC_WRITE,
       0,
       NULL,
       CREATE_ALWAYS,
       fileflags,
       NULL
    );

    sqliteFree(zWide);
  }else{
#if OS_WINCE
    return SQLITE_NOMEM;
#else


    h = CreateFileA(zFilename,
       GENERIC_READ | GENERIC_WRITE,
       0,
       NULL,
       CREATE_ALWAYS,
       fileflags,
       NULL
    );

#endif /* OS_WINCE */
  }
  if( h==INVALID_HANDLE_VALUE ){
    return SQLITE_CANTOPEN;
  }
  f.h = h;
#if OS_WINCE
................................................................................
}

/*
** Close a file.
*/
static int winClose(OsFile **pId){
  winFile *pFile;

  if( pId && (pFile = (winFile*)*pId)!=0 ){

    TRACE2("CLOSE %d\n", pFile->h);

    CloseHandle(pFile->h);

#if OS_WINCE
    winceDestroyLock(pFile);
    if( pFile->zDeleteOnClose ){
      DeleteFileW(pFile->zDeleteOnClose);
      sqliteFree(pFile->zDeleteOnClose);
    }
#endif
    OpenCounter(-1);
    sqliteFree(pFile);
    *pId = 0;
  }
  return SQLITE_OK;
}

/*
** Read data from a file into a buffer.  Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
*/







>
>

>
|
>





>
|
>



|







 







>
>
|
|
|
|
|
|
|
|
>





>
>
|
|
|
|
|
|
|
|
>







 







>

>

>
|
>











|







476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
...
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
#endif /* OS_WINCE */

/*
** Delete the named file
*/
int sqlite3WinDelete(const char *zFilename){
  WCHAR *zWide = utf8ToUnicode(zFilename);
  int cnt = 0;
  int rc;
  if( zWide ){
    do{
      rc = DeleteFileW(zWide);
    }while( rc==0 && cnt++ < 3 && (Sleep(100), 1) );
    sqliteFree(zWide);
  }else{
#if OS_WINCE
    return SQLITE_NOMEM;
#else
    do{
      rc = DeleteFileA(zFilename);
    }while( rc==0 && cnt++ < 3 && (Sleep(100), 1) );
#endif
  }
  TRACE2("DELETE \"%s\"\n", zFilename);
  return rc==0 ? SQLITE_OK : SQLITE_IOERR;
}

/*
** Return TRUE if the named file exists.
*/
int sqlite3WinFileExists(const char *zFilename){
  int exists = 0;
................................................................................
  fileflags = FILE_FLAG_RANDOM_ACCESS;
#if !OS_WINCE
  if( delFlag ){
    fileflags |= FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE;
  }
#endif
  if( zWide ){
    int cnt = 0;
    do{
      h = CreateFileW(zWide,
         GENERIC_READ | GENERIC_WRITE,
         0,
         NULL,
         CREATE_ALWAYS,
         fileflags,
         NULL
      );
    }while( h==INVALID_HANDLE_VALUE && cnt++ < 2 && (Sleep(100), 1) );
    sqliteFree(zWide);
  }else{
#if OS_WINCE
    return SQLITE_NOMEM;
#else
    int cnt = 0;
    do{
      h = CreateFileA(zFilename,
        GENERIC_READ | GENERIC_WRITE,
        0,
        NULL,
        CREATE_ALWAYS,
        fileflags,
        NULL
      );
    }while( h==INVALID_HANDLE_VALUE && cnt++ < 2 && (Sleep(100), 1) );
#endif /* OS_WINCE */
  }
  if( h==INVALID_HANDLE_VALUE ){
    return SQLITE_CANTOPEN;
  }
  f.h = h;
#if OS_WINCE
................................................................................
}

/*
** Close a file.
*/
static int winClose(OsFile **pId){
  winFile *pFile;
  int rc = 1;
  if( pId && (pFile = (winFile*)*pId)!=0 ){
    int rc, cnt = 0;
    TRACE2("CLOSE %d\n", pFile->h);
    do{
      rc = CloseHandle(pFile->h);
    }while( rc==0 && cnt++ < 3 && (Sleep(100), 1) );
#if OS_WINCE
    winceDestroyLock(pFile);
    if( pFile->zDeleteOnClose ){
      DeleteFileW(pFile->zDeleteOnClose);
      sqliteFree(pFile->zDeleteOnClose);
    }
#endif
    OpenCounter(-1);
    sqliteFree(pFile);
    *pId = 0;
  }
  return rc ? SQLITE_OK : SQLITE_IOERR;
}

/*
** Read data from a file into a buffer.  Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
*/