Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add unix-only tests to check that the "unzip" program can unpack archives generated by the zipfile extension. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
438c5c5237a801ae78809bf324bb9251 |
User & Date: | dan 2018-01-29 19:47:32.262 |
Context
2018-01-30
| ||
14:07 | Prevent users from creating zipfile() virtual tables without an argument. (check-in: 81fdbe0cc5 user: dan tags: trunk) | |
2018-01-29
| ||
19:47 | Add unix-only tests to check that the "unzip" program can unpack archives generated by the zipfile extension. (check-in: 438c5c5237 user: dan tags: trunk) | |
18:41 | Add aggregate function zipfile() to the zipfile extension. For composing new zip archives in memory. (check-in: e364eeac76 user: dan tags: trunk) | |
Changes
Changes to ext/misc/fileio.c.
︙ | ︙ | |||
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | int i; for(i=0; i<=pCur->iLvl; i++){ FsdirLevel *pLvl = &pCur->aLvl[i]; if( pLvl->pDir ) closedir(pLvl->pDir); sqlite3_free(pLvl->zDir); } sqlite3_free(pCur->zPath); pCur->aLvl = 0; pCur->zPath = 0; pCur->zBase = 0; pCur->nBase = 0; pCur->iLvl = -1; pCur->iRowid = 1; } /* ** Destructor for an fsdir_cursor. */ static int fsdirClose(sqlite3_vtab_cursor *cur){ fsdir_cursor *pCur = (fsdir_cursor*)cur; fsdirResetCursor(pCur); | > < | 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | int i; for(i=0; i<=pCur->iLvl; i++){ FsdirLevel *pLvl = &pCur->aLvl[i]; if( pLvl->pDir ) closedir(pLvl->pDir); sqlite3_free(pLvl->zDir); } sqlite3_free(pCur->zPath); sqlite3_free(pCur->aLvl); pCur->aLvl = 0; pCur->zPath = 0; pCur->zBase = 0; pCur->nBase = 0; pCur->iLvl = -1; pCur->iRowid = 1; } /* ** Destructor for an fsdir_cursor. */ static int fsdirClose(sqlite3_vtab_cursor *cur){ fsdir_cursor *pCur = (fsdir_cursor*)cur; fsdirResetCursor(pCur); sqlite3_free(pCur); return SQLITE_OK; } /* ** Set the error message for the virtual table associated with cursor ** pCur to the results of vprintf(zFmt, ...). |
︙ | ︙ |
Changes to test/zipfile.test.
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | proc readfile {f} { set fd [open $f] fconfigure $fd -translation binary -encoding binary set data [read $fd] close $fd set data } # Argument $file is the name of a zip archive on disk. This function # executes test cases to check that the results of each of the following # are the same: # # SELECT * FROM zipfile($file) # SELECT * FROM zipfile( readfile($file) ) | > > > > > > > > > > > > > > > > > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | proc readfile {f} { set fd [open $f] fconfigure $fd -translation binary -encoding binary set data [read $fd] close $fd set data } if {$::tcl_platform(platform)=="unix" && [catch {exec unzip}]==0} { set ::UNZIP 1 load_static_extension db fileio proc do_unzip {file} { forcedelete test_unzip file mkdir test_unzip exec unzip -d test_unzip $file set res [db eval { SELECT replace(name,'test_unzip/',''),mode,mtime,data FROM fsdir('test_unzip') WHERE name!='test_unzip' ORDER BY name }] set res } } # Argument $file is the name of a zip archive on disk. This function # executes test cases to check that the results of each of the following # are the same: # # SELECT * FROM zipfile($file) # SELECT * FROM zipfile( readfile($file) ) |
︙ | ︙ | |||
54 55 56 57 58 59 60 | set r2 [db eval $q2] set r3 [db eval $q3] #puts $r1 #puts $r2 #puts $r3 uplevel [list do_test $tn.1 [list set {} $r2] $r1] | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | set r2 [db eval $q2] set r3 [db eval $q3] #puts $r1 #puts $r2 #puts $r3 uplevel [list do_test $tn.1 [list set {} $r2] $r1] uplevel [list do_test $tn.2 [list set {} $r3] $r1] } # Argument $file is a zip file on disk. This command runs tests to: # # 1. Unpack the archive with unix command [unzip] and compare the # results to reading the same archive using the zipfile() table # valued function. # # 2. Creates a new archive with the same contents using the zipfile() # aggregate function as follows: # # SELECT writefile('test_unzip.zip', # ( SELECT zipfile(name,mode,mtime,data,method) FROM zipfile($file) ) # ); # # Then tests that unpacking the new archive using [unzip] produces # the same results as in (1). # proc do_unzip_test {tn file} { if {[info vars ::UNZIP]==""} { return } db func sss strip_slash db eval { SELECT writefile('test_unzip.zip', ( SELECT zipfile(name,mode,mtime,data,method) FROM zipfile($file) ) ); } set r1 [db eval { SELECT sss(name),mode,mtime,data FROM zipfile($file) ORDER BY name }] set r2 [do_unzip $file] set r3 [do_unzip test_unzip.zip] uplevel [list do_test $tn.1 [list set {} $r2] $r1] uplevel [list do_test $tn.2 [list set {} $r3] $r1] } proc strip_slash {in} { regsub {/$} $in {} } proc do_zip_tests {tn file} { uplevel do_zipfile_blob_test $tn.1 $file uplevel do_unzip_test $tn.2 $file } forcedelete test.zip do_execsql_test 1.0 { CREATE VIRTUAL TABLE temp.zz USING zipfile('test.zip'); PRAGMA table_info(zz); } { |
︙ | ︙ | |||
95 96 97 98 99 100 101 | do_execsql_test 1.2 { SELECT name, mtime, data FROM zipfile('test.zip') } { f.txt 1000000000 abcde g.txt 1000000002 12345 } | | | | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | do_execsql_test 1.2 { SELECT name, mtime, data FROM zipfile('test.zip') } { f.txt 1000000000 abcde g.txt 1000000002 12345 } do_zip_tests 1.2a test.zip do_execsql_test 1.3 { INSERT INTO zz(name, mode, mtime, data) VALUES('h.txt', '-rw-r--r--', 1000000004, 'aaaaaaaaaabbbbbbbbbb' ); } do_zip_tests 1.3a test.zip do_execsql_test 1.4 { SELECT name, mtime, data, method FROM zipfile('test.zip'); } { f.txt 1000000000 abcde 0 g.txt 1000000002 12345 0 h.txt 1000000004 aaaaaaaaaabbbbbbbbbb 8 |
︙ | ︙ | |||
149 150 151 152 153 154 155 | do_execsql_test 1.6.1 { SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { f.txt 33188 1000000000 abcde 0 h.txt 33188 1000000004 aaaaaaaaaabbbbbbbbbb 8 i.txt 33188 1000000006 zxcvb 0 } | | | | | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | do_execsql_test 1.6.1 { SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { f.txt 33188 1000000000 abcde 0 h.txt 33188 1000000004 aaaaaaaaaabbbbbbbbbb 8 i.txt 33188 1000000006 zxcvb 0 } do_zip_tests 1.6.1a test.zip do_execsql_test 1.6.2 { UPDATE zz SET mtime=4 WHERE name='i.txt'; SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { f.txt 33188 1000000000 abcde 0 h.txt 33188 1000000004 aaaaaaaaaabbbbbbbbbb 8 i.txt 33188 4 zxcvb 0 } do_execsql_test 1.6.3 { UPDATE zz SET mode='-rw-r--r-x' WHERE name='h.txt'; SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { f.txt 33188 1000000000 abcde 0 h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8 i.txt 33188 4 zxcvb 0 } do_zip_tests 1.6.3a test.zip do_execsql_test 1.6.4 { UPDATE zz SET name = 'blue.txt' WHERE name='f.txt'; SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { blue.txt 33188 1000000000 abcde 0 h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8 i.txt 33188 4 zxcvb 0 } do_zip_tests 1.6.4a test.zip do_execsql_test 1.6.5 { UPDATE zz SET data = 'edcba' WHERE name='blue.txt'; SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { blue.txt 33188 1000000000 edcba 0 h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8 |
︙ | ︙ | |||
213 214 215 216 217 218 219 220 221 222 223 224 225 226 | i.txt 33188 4 zxcvb 0 } #------------------------------------------------------------------------- db close forcedelete test.zip reset_db load_static_extension db zipfile do_execsql_test 2.1 { CREATE VIRTUAL TABLE zzz USING zipfile('test.zip'); INSERT INTO zzz(name, mode) VALUES('dirname', 'drwxr-xr-x'); SELECT name, mode, data FROM zzz; } {dirname/ 16877 {}} do_execsql_test 2.2 { | > | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | i.txt 33188 4 zxcvb 0 } #------------------------------------------------------------------------- db close forcedelete test.zip reset_db load_static_extension db fileio load_static_extension db zipfile do_execsql_test 2.1 { CREATE VIRTUAL TABLE zzz USING zipfile('test.zip'); INSERT INTO zzz(name, mode) VALUES('dirname', 'drwxr-xr-x'); SELECT name, mode, data FROM zzz; } {dirname/ 16877 {}} do_execsql_test 2.2 { |
︙ | ︙ | |||
239 240 241 242 243 244 245 | do_execsql_test 2.4 { SELECT name, mode, data FROM zzz; } { dirname3/ 16877 {} dirname2/ 16877 {} dirname2/file1.txt 33188 abcdefghijklmnop } | | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | do_execsql_test 2.4 { SELECT name, mode, data FROM zzz; } { dirname3/ 16877 {} dirname2/ 16877 {} dirname2/file1.txt 33188 abcdefghijklmnop } do_zip_tests 2.4a test.zip # If on unix, check that the [unzip] utility can unpack our archive. # if {$::tcl_platform(platform)=="unix"} { do_test 2.5.1 { forcedelete dirname forcedelete dirname2 |
︙ | ︙ |