SQLite

Check-in [ebfb04f00c]
Login

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

Overview
Comment:Change code in malloc_common.tcl (test code) to retry a "file delete -force" if it fails.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ebfb04f00c839601d92d33b9c2305fc4ce869bbc
User & Date: dan 2010-09-16 15:23:07.000
Context
2010-09-16
15:58
Fix a problem with the previous change to malloc_common.tcl. (check-in: e07a33ea0f user: dan tags: trunk)
15:23
Change code in malloc_common.tcl (test code) to retry a "file delete -force" if it fails. (check-in: ebfb04f00c user: dan tags: trunk)
2010-09-15
23:41
Updates to the sqlite3_progress_handler() documentation. (check-in: 78f659ee9b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/malloc_common.tcl.
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#   faultsim_save
#   faultsim_restore
#   faultsim_save_and_close
#   faultsim_restore_and_reopen
#   faultsim_delete_and_reopen
#
proc faultsim_save {} {
  foreach f [glob -nocomplain sv_test.db*] { file delete -force $f }
  foreach f [glob -nocomplain test.db*] {
    set f2 "sv_$f"
    file copy -force $f $f2
  }
}
proc faultsim_save_and_close {} {
  faultsim_save
  catch { db close }
  return ""
}
proc faultsim_restore {} {
  foreach f [glob -nocomplain test.db*] { file delete -force $f }
  foreach f2 [glob -nocomplain sv_test.db*] {
    set f [string range $f2 3 end]
    file copy -force $f2 $f
  }
}
proc faultsim_restore_and_reopen {{dbfile test.db}} {
  catch { db close }







|











|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#   faultsim_save
#   faultsim_restore
#   faultsim_save_and_close
#   faultsim_restore_and_reopen
#   faultsim_delete_and_reopen
#
proc faultsim_save {} {
  foreach f [glob -nocomplain sv_test.db*] { forcedelete $f }
  foreach f [glob -nocomplain test.db*] {
    set f2 "sv_$f"
    file copy -force $f $f2
  }
}
proc faultsim_save_and_close {} {
  faultsim_save
  catch { db close }
  return ""
}
proc faultsim_restore {} {
  foreach f [glob -nocomplain test.db*] { forcedelete $f }
  foreach f2 [glob -nocomplain sv_test.db*] {
    set f [string range $f2 3 end]
    file copy -force $f2 $f
  }
}
proc faultsim_restore_and_reopen {{dbfile test.db}} {
  catch { db close }
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
  
        # Remove all traces of database files test.db and test2.db 
        # from the file-system. Then open (empty database) "test.db" 
        # with the handle [db].
        # 
        catch {db close} 
        catch {db2 close} 
        catch {file delete -force test.db}
        catch {file delete -force test.db-journal}
        catch {file delete -force test.db-wal}
        catch {file delete -force test2.db}
        catch {file delete -force test2.db-journal}
        catch {file delete -force test2.db-wal}
        if {[info exists ::mallocopts(-testdb)]} {
          file copy $::mallocopts(-testdb) test.db
        }
        catch { sqlite3 db test.db }
        if {[info commands db] ne ""} {
          sqlite3_extended_result_codes db 1
        }







|
|
|
|
|
|







418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
  
        # Remove all traces of database files test.db and test2.db 
        # from the file-system. Then open (empty database) "test.db" 
        # with the handle [db].
        # 
        catch {db close} 
        catch {db2 close} 
        forcedelete test.db
        forcedelete test.db-journal
        forcedelete test.db-wal
        forcedelete test2.db
        forcedelete test2.db-journal
        forcedelete test2.db-wal
        if {[info exists ::mallocopts(-testdb)]} {
          file copy $::mallocopts(-testdb) test.db
        }
        catch { sqlite3 db test.db }
        if {[info commands db] ne ""} {
          sqlite3_extended_result_codes db 1
        }
Changes to test/tester.tcl.
597
598
599
600
601
602
603












604
605
606

607
608
609
610
611
612
613
  }
  return $r
}

# Delete a file or directory
#
proc forcedelete {filename} {












  if {[catch {file delete -force $filename}]} {
    exec rm -rf $filename
  }

}

# Do an integrity check of the entire database
#
proc integrity_check {name {db db}} {
  ifcapable integrityck {
    do_test $name [list execsql {PRAGMA integrity_check} $db] {ok}







>
>
>
>
>
>
>
>
>
>
>
>
|
<

>







597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
  }
  return $r
}

# Delete a file or directory
#
proc forcedelete {filename} {
  # On windows, sometimes even a [file delete -force] can fail just after
  # a file is closed. The cause is usually "tag-alongs" - programs like
  # anti-virus software, automatic backup tools and various explorer
  # extensions that keep a file open a little longer than we expect, causing
  # the delete to fail.
  #
  # The solution is to wait a short amount of time before retrying the delete.
  #
  set nRetry  50                  ;# Maximum number of retries.
  set nDelay 100                  ;# Delay in ms before retrying.
  set rc 1
  for {set i 0} {$i<$nRetry && $rc} {incr i} {
    set rc [catch {file delete -force $filename} msg]

  }
  if {$rc} { error $msg }
}

# Do an integrity check of the entire database
#
proc integrity_check {name {db db}} {
  ifcapable integrityck {
    do_test $name [list execsql {PRAGMA integrity_check} $db] {ok}