1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-09-02 12:21:26 +03:00

Add stdio support to the quota VFS.

FossilOrigin-Name: 322bd15f97143d39b3a88d5f6cf7afb454e0666e
This commit is contained in:
drh
2011-12-15 17:44:33 +00:00
7 changed files with 1197 additions and 38 deletions

87
test/quota-glob.test Normal file
View File

@@ -0,0 +1,87 @@
# 2011 December 1
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Tests for the glob-style string compare operator embedded in the
# quota shim.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
catch { unset testnum }
catch { unset pattern }
catch { unset text }
catch { unset ans }
foreach {testnum pattern text ans} {
1 abcdefg abcdefg 1
2 abcdefG abcdefg 0
3 abcdef abcdefg 0
4 abcdefgh abcdefg 0
5 abcdef? abcdefg 1
6 abcdef? abcdef 0
7 abcdef? abcdefgh 0
8 abcdefg abcdef? 0
9 abcdef? abcdef? 1
10 abc/def abc/def 1
11 abc//def abc/def 0
12 */abc/* x/abc/y 1
13 */abc/* /abc/ 1
16 */abc/* x///a/ab/abc 0
17 */abc/* x//a/ab/abc/ 1
16 */abc/* x///a/ab/abc 0
17 */abc/* x//a/ab/abc/ 1
18 **/abc/** x//a/ab/abc/ 1
19 *?/abc/*? x//a/ab/abc/y 1
20 ?*/abc/?* x//a/ab/abc/y 1
21 {abc[cde]efg} abcbefg 0
22 {abc[cde]efg} abccefg 1
23 {abc[cde]efg} abcdefg 1
24 {abc[cde]efg} abceefg 1
25 {abc[cde]efg} abcfefg 0
26 {abc[^cde]efg} abcbefg 1
27 {abc[^cde]efg} abccefg 0
28 {abc[^cde]efg} abcdefg 0
29 {abc[^cde]efg} abceefg 0
30 {abc[^cde]efg} abcfefg 1
31 {abc[c-e]efg} abcbefg 0
32 {abc[c-e]efg} abccefg 1
33 {abc[c-e]efg} abcdefg 1
34 {abc[c-e]efg} abceefg 1
35 {abc[c-e]efg} abcfefg 0
36 {abc[^c-e]efg} abcbefg 1
37 {abc[^c-e]efg} abccefg 0
38 {abc[^c-e]efg} abcdefg 0
39 {abc[^c-e]efg} abceefg 0
40 {abc[^c-e]efg} abcfefg 1
41 {abc[c-e]efg} abc-efg 0
42 {abc[-ce]efg} abc-efg 1
43 {abc[ce-]efg} abc-efg 1
44 {abc[][*?]efg} {abc]efg} 1
45 {abc[][*?]efg} {abc*efg} 1
46 {abc[][*?]efg} {abc?efg} 1
47 {abc[][*?]efg} {abc[efg} 1
48 {abc[^][*?]efg} {abc]efg} 0
49 {abc[^][*?]efg} {abc*efg} 0
50 {abc[^][*?]efg} {abc?efg} 0
51 {abc[^][*?]efg} {abc[efg} 0
52 {abc[^][*?]efg} {abcdefg} 1
53 {*[xyz]efg} {abcxefg} 1
54 {*[xyz]efg} {abcwefg} 0
} {
do_test quota-glob-$testnum.1 {
sqlite3_quota_glob $::pattern $::text
} $::ans
do_test quota-glob-$testnum.2 {
sqlite3_quota_glob $::pattern [string map {/ \\} $::text]
} $::ans
}
finish_test

View File

@@ -50,6 +50,7 @@ do_test quota-1.8 { sqlite3_quota_shutdown } {SQLITE_OK}
#
sqlite3_quota_initialize "" 1
unset -nocomplain quota_request_ok
proc quota_check {filename limitvar size} {
upvar $limitvar limit

236
test/quota2.test Normal file
View File

@@ -0,0 +1,236 @@
# 2011 December 1
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
db close
sqlite3_quota_initialize "" 1
foreach dir {quota2a/x1 quota2a/x2 quota2a quota2b quota2c} {
file delete -force $dir
}
foreach dir {quota2a quota2a/x1 quota2a/x2 quota2b quota2c} {
file mkdir $dir
}
# The standard_path procedure converts a pathname into a standard format
# that is the same across platforms.
#
unset -nocomplain ::quota_pwd ::quota_mapping
set ::quota_pwd [string map {\\ /} [pwd]]
set ::quota_mapping [list $::quota_pwd PWD]
proc standard_path {x} {
set x [string map {\\ /} $x]
return [string map $::quota_mapping $x]
}
# The quota_check procedure is a callback from the quota handler.
# It has three arguments which are (1) the full pathname of the file
# that has gone over quota, (2) the quota limit, (3) the requested
# new quota size to cover the last write. These three values are
# appended to the global variable $::quota. The filename is processed
# to convert every \ character into / and to change the name of the
# working directory to PWD.
#
# The quota is increased to the request if the ::quota_request_ok
# global variable is true.
#
set ::quota {}
set ::quota_request_ok 0
proc quota_check {filename limitvar size} {
upvar $limitvar limit
lappend ::quota [standard_path $filename] [set limit] $size
if {$::quota_request_ok} {set limit $size}
}
sqlite3_quota_set */quota2a/* 4000 quota_check
sqlite3_quota_set */quota2b/* 5000 quota_check
unset -nocomplain bigtext
for {set i 1} {$i<=1000} {incr i} {
if {$i%10==0} {
append bigtext [format "%06d\n" $i]
} else {
append bigtext [format "%06d " $i]
}
}
catch { unset h1 }
catch { unset x }
do_test quota2-1.1 {
set ::h1 [sqlite3_quota_fopen quota2a/xyz.txt w+b]
sqlite3_quota_fwrite $::h1 1 7000 $bigtext
} {4000}
do_test quota2-1.2 {
set ::quota
} {PWD/quota2a/xyz.txt 4000 7000}
do_test quota2-1.3 {
sqlite3_quota_rewind $::h1
set ::x [sqlite3_quota_fread $::h1 1001 7]
string length $::x
} {3003}
do_test quota2-1.4 {
string match $::x [string range $::bigtext 0 3002]
} {1}
do_test quota2-1.5 {
sqlite3_quota_fseek $::h1 0 SEEK_END
sqlite3_quota_ftell $::h1
} {4000}
do_test quota2-1.6 {
sqlite3_quota_fseek $::h1 -100 SEEK_END
sqlite3_quota_ftell $::h1
} {3900}
do_test quota2-1.7 {
sqlite3_quota_fseek $::h1 -100 SEEK_CUR
sqlite3_quota_ftell $::h1
} {3800}
do_test quota2-1.8 {
sqlite3_quota_fseek $::h1 50 SEEK_CUR
sqlite3_quota_ftell $::h1
} {3850}
do_test quota2-1.9 {
sqlite3_quota_fseek $::h1 50 SEEK_SET
sqlite3_quota_ftell $::h1
} {50}
do_test quota2-1.10 {
sqlite3_quota_rewind $::h1
sqlite3_quota_ftell $::h1
} {0}
do_test quota2-1.11 {
standard_path [sqlite3_quota_dump]
} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 1 0}}}
do_test quota2-1.12 {
sqlite3_quota_fclose $::h1
standard_path [sqlite3_quota_dump]
} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 0 0}}}
do_test quota2-1.13 {
sqlite3_quota_remove quota2a/xyz.txt
standard_path [sqlite3_quota_dump]
} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
set quota {}
do_test quota2-2.1 {
set ::h1 [sqlite3_quota_fopen quota2c/xyz.txt w+b]
sqlite3_quota_fwrite $::h1 1 7000 $bigtext
} {7000}
do_test quota2-2.2 {
set ::quota
} {}
do_test quota2-2.3 {
sqlite3_quota_rewind $::h1
set ::x [sqlite3_quota_fread $::h1 1001 7]
string length $::x
} {6006}
do_test quota2-2.4 {
string match $::x [string range $::bigtext 0 6005]
} {1}
do_test quota2-2.5 {
sqlite3_quota_fseek $::h1 0 SEEK_END
sqlite3_quota_ftell $::h1
} {7000}
do_test quota2-2.6 {
sqlite3_quota_fseek $::h1 -100 SEEK_END
sqlite3_quota_ftell $::h1
} {6900}
do_test quota2-2.7 {
sqlite3_quota_fseek $::h1 -100 SEEK_CUR
sqlite3_quota_ftell $::h1
} {6800}
do_test quota2-2.8 {
sqlite3_quota_fseek $::h1 50 SEEK_CUR
sqlite3_quota_ftell $::h1
} {6850}
do_test quota2-2.9 {
sqlite3_quota_fseek $::h1 50 SEEK_SET
sqlite3_quota_ftell $::h1
} {50}
do_test quota2-2.10 {
sqlite3_quota_rewind $::h1
sqlite3_quota_ftell $::h1
} {0}
do_test quota2-2.11 {
standard_path [sqlite3_quota_dump]
} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
do_test quota2-2.12 {
sqlite3_quota_fclose $::h1
standard_path [sqlite3_quota_dump]
} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
do_test quota2-3.1 {
sqlite3_quota_set */quota2b/* 0 quota_check
set ::h1 [sqlite3_quota_fopen quota2a/x1/a.txt a]
sqlite3_quota_fwrite $::h1 10 10 $bigtext
} {10}
do_test quota2-3.2 {
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
do_test quota2-3.3a {
sqlite3_quota_fflush $::h1 0
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
do_test quota2-3.3b {
sqlite3_quota_fflush $::h1 1
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
do_test quota2-3.3c {
sqlite3_quota_fflush $::h1
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
do_test quota2-3.4 {
sqlite3_quota_fclose $::h1
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 0 0}}}
do_test quota2-3.5 {
set ::h2 [sqlite3_quota_fopen quota2a/x2/b.txt a]
sqlite3_quota_fwrite $::h2 10 20 $bigtext
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 300 {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}
do_test quota2-3.6 {
set ::h3 [sqlite3_quota_fopen quota2a/x1/c.txt a]
sqlite3_quota_fwrite $::h3 10 50 $bigtext
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 800 {PWD/quota2a/x1/c.txt 500 1 0} {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}
do_test quota2-3.7 {
file exists quota2a/x1/a.txt
} {1}
do_test quota2-3.8 {
file exists quota2a/x2/b.txt
} {1}
do_test quota2-3.9 {
file exists quota2a/x1/c.txt
} {1}
do_test quota2-3.10 {
sqlite3_quota_remove quota2a/x1
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 700 {PWD/quota2a/x1/c.txt 500 1 1} {PWD/quota2a/x2/b.txt 200 1 0}}}
do_test quota2-3.11 {
sqlite3_quota_fclose $::h2
sqlite3_quota_fclose $::h3
standard_path [sqlite3_quota_dump]
} {{*/quota2a/* 4000 200 {PWD/quota2a/x2/b.txt 200 0 0}}}
do_test quota2-3.12 {
file exists quota2a/x1/a.txt
} {0}
do_test quota2-3.13 {
file exists quota2a/x2/b.txt
} {1}
do_test quota2-3.14 {
file exists quota2a/x1/c.txt
} {0}
catch { sqlite3_quota_shutdown }
catch { unset quota_request_ok }
finish_test