/ Check-in [54a38555]
Login

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

Overview
Comment:Adjust copy_file() lsmtest function so it works properly for locked database files on Win32.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 54a3855583deac93c955ed77fe82be6a6b7aadd3fdb7e6b895888e2a4ff530bd
User & Date: mistachkin 2017-07-07 20:35:14
Context
2017-07-07
21:15
For lsmtest, use a more portable means of setting open() files to binary. check-in: aea6e0ff user: mistachkin tags: trunk
20:35
Adjust copy_file() lsmtest function so it works properly for locked database files on Win32. check-in: 54a38555 user: mistachkin tags: trunk
20:06
Add the "PRAGMA secure_delete=FAST" option, which overwrites most deleted content without increasing the amount of I/O. Deleted content might persist on the free page list, however. And extra CPU cycles are used for zeroing, of course. check-in: 38978ce6 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/lsm1/lsm-test/lsmtest6.c.

   253    253     unlink(zFile);
   254    254     unlink(zLog);
   255    255     unlink(zShm);
   256    256     testFree(zLog);
   257    257     testFree(zShm);
   258    258   }
   259    259   
   260         -static void copy_file(const char *zFrom, const char *zTo){
          260  +static void copy_file(const char *zFrom, const char *zTo, int isDatabase){
   261    261   
   262    262     if( access(zFrom, F_OK) ){
   263    263       unlink(zTo);
   264    264     }else{
   265    265       int fd1;
   266    266       int fd2;
   267    267       off_t sz;
................................................................................
   274    274   
   275    275       fstat(fd1, &buf);
   276    276       sz = buf.st_size;
   277    277       ftruncate(fd2, sz);
   278    278   
   279    279       aBuf = testMalloc(4096);
   280    280       for(i=0; i<sz; i+=4096){
   281         -      int nByte = MIN(4096, sz - i);
          281  +      int bLockPage = isDatabase && i == 0;
          282  +      int nByte = MIN((bLockPage ? 4066 : 4096), sz - i);
          283  +      memset(aBuf, 0, 4096);
   282    284         read(fd1, aBuf, nByte);
   283    285         write(fd2, aBuf, nByte);
          286  +      if( bLockPage ){
          287  +        lseek(fd1, 4096, SEEK_SET);
          288  +        lseek(fd2, 4096, SEEK_SET);
          289  +      }
   284    290       }
   285    291       testFree(aBuf);
   286    292   
   287    293       close(fd1);
   288    294       close(fd2);
   289    295     }
   290    296   }
................................................................................
   294    300     char *zLog2 = testMallocPrintf("%s-log", zTo);
   295    301     char *zShm1 = testMallocPrintf("%s-shm", zFrom);
   296    302     char *zShm2 = testMallocPrintf("%s-shm", zTo);
   297    303   
   298    304     unlink(zShm2);
   299    305     unlink(zLog2);
   300    306     unlink(zTo);
   301         -  copy_file(zFrom, zTo);
   302         -  copy_file(zLog1, zLog2);
   303         -  copy_file(zShm1, zShm2);
          307  +  copy_file(zFrom, zTo, 1);
          308  +  copy_file(zLog1, zLog2, 0);
          309  +  copy_file(zShm1, zShm2, 0);
   304    310   
   305    311     testFree(zLog1); testFree(zLog2); testFree(zShm1); testFree(zShm2);
   306    312   }
   307    313   
   308    314   /*
   309    315   ** File zFile is the path to a database. This function makes backups
   310    316   ** of the database file and its log as follows:
................................................................................
   318    324   void testSaveDb(const char *zFile, const char *zAux){
   319    325     char *zLog = testMallocPrintf("%s-%s", zFile, zAux);
   320    326     char *zFileSave = testMallocPrintf("%s-save", zFile);
   321    327     char *zLogSave = testMallocPrintf("%s-%s-save", zFile, zAux);
   322    328   
   323    329     unlink(zFileSave);
   324    330     unlink(zLogSave);
   325         -  copy_file(zFile, zFileSave);
   326         -  copy_file(zLog, zLogSave);
          331  +  copy_file(zFile, zFileSave, 1);
          332  +  copy_file(zLog, zLogSave, 0);
   327    333   
   328    334     testFree(zLog); testFree(zFileSave); testFree(zLogSave);
   329    335   }
   330    336   
   331    337   /*
   332    338   ** File zFile is the path to a database. This function restores
   333    339   ** a backup of the database made by a previous call to testSaveDb().
................................................................................
   337    343   **     cp $(zFile)-save-$(zAux) $(zFile)-$(zAux)
   338    344   */
   339    345   void testRestoreDb(const char *zFile, const char *zAux){
   340    346     char *zLog = testMallocPrintf("%s-%s", zFile, zAux);
   341    347     char *zFileSave = testMallocPrintf("%s-save", zFile);
   342    348     char *zLogSave = testMallocPrintf("%s-%s-save", zFile, zAux);
   343    349   
   344         -  copy_file(zFileSave, zFile);
   345         -  copy_file(zLogSave, zLog);
          350  +  copy_file(zFileSave, zFile, 1);
          351  +  copy_file(zLogSave, zLog, 0);
   346    352   
   347    353     testFree(zLog); testFree(zFileSave); testFree(zLogSave);
   348    354   }
   349    355   
   350    356   
   351    357   static int lsmWriteStr(lsm_db *pDb, const char *zKey, const char *zVal){
   352    358     int nKey = strlen(zKey);

Changes to ext/lsm1/lsm-test/lsmtest_main.c.

     7      7   #include "stdlib.h"
     8      8   
     9      9   #include <sqlite3.h>
    10     10   
    11     11   #ifndef _WIN32
    12     12   # include <unistd.h>
    13     13   #endif
           14  +#include <stdlib.h>
    14     15   #include <sys/types.h>
    15     16   #include <sys/stat.h>
    16     17   #include <fcntl.h>
    17     18   #include <errno.h>
    18     19   
    19     20   
    20     21   void test_failed(){ 
................................................................................
  1517   1518   
  1518   1519   #ifdef LSM_DEBUG_MEM
  1519   1520     FILE *pReport = 0;              /* lsm malloc() report file */
  1520   1521     const char *zReport = "malloc.txt generated";
  1521   1522   #else
  1522   1523     const char *zReport = "malloc.txt NOT generated";
  1523   1524   #endif
         1525  +
         1526  +#if defined(_MSC_VER) || defined(__MSVCRT__)
         1527  +  _set_fmode(_O_BINARY);
         1528  +#endif
  1524   1529   
  1525   1530     testMallocInstall(tdb_lsm_env());
  1526   1531   
  1527   1532     if( argc<2 ){
  1528   1533       testPrintError("Usage: %s sub-command ?args...?\n", argv[0]);
  1529   1534       return -1;
  1530   1535     }