From 2ad0949db4fbaca1a92a6fdf9957842cb6492366 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 9 Dec 2017 18:28:22 +0000 Subject: [PATCH] Add support for -C to ".ar x". FossilOrigin-Name: 8cd70960c5ddf0d0b2c40b8b6af4ce6b0277ffdaf04f33fcb33227d2b99ad515 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 18 ++++++++++++++++-- test/shell8.test | 13 +++++++++++-- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 98adac2007..1916921b89 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sparsing\sof\s".ar"\scommands.\sAdd\snew\stest\sfile\sfor\sthe\ssame. -D 2017-12-09T17:58:02.648 +C Add\ssupport\sfor\s-C\sto\s".ar\sx". +D 2017-12-09T18:28:22.916 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 6a879cbf01e37f9eac131414955f71774b566502d9a57ded1b8585b507503cb8 @@ -474,7 +474,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 17e220191860a64a18c084141e1a8b7309e166a6f2d42c02021af27ea080d157 -F src/shell.c.in 907661eeab82949420270b24f5989a399242cb8721e6140f73b3a46939fc4820 +F src/shell.c.in 8e57abbd26d7d2344ba752be0f86b2cbf93ad73ca28c651786392fbfd3b512ba F src/sqlite.h.in 8fd97993d48b50b9bade38c52f12d175942c9497c960905610c7b03a3e4b5818 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h c02d628cca67f3889c689d82d25c3eb45e2c155db08e4c6089b5840d64687d34 @@ -1214,7 +1214,7 @@ F test/shell4.test 89ad573879a745974ff2df20ff97c5d6ffffbd5d F test/shell5.test 23939a4c51f0421330ea61dbd3c74f9c215f5f8d3d1a94846da6ffc777a35458 F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3 F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f -F test/shell8.test 98b1d7b218060e557b3a789f3396635a0c03873ea652b3154c7f3f238d4a1a8f +F test/shell8.test 0e8e064da50c92df8eb514202dcfd0020f71762250066bf41ed098e0ff5f0e3d F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 F test/shrink.test 1b4330b1fd9e818c04726d45cb28db73087535ce @@ -1682,7 +1682,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0cc699d14adfe8c7b7be50c180186562861806c47425c80c935bce43ee5c5c12 -R 0b3e6167ae82d64c1e021b537a83d40a +P 840401cc8ce3a09e0663b46973ecd2856d9607be71d2d1e9b21f7df7a82dcbe5 +R e8ce05071b1dec8c5193e0b4d7b226fe U dan -Z 9b95380c27ad603c463b4469d523a6d2 +Z f3cf78b2d0eddbe511b3f9a244339aaa diff --git a/manifest.uuid b/manifest.uuid index d1e1c772f3..b240d7b3d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -840401cc8ce3a09e0663b46973ecd2856d9607be71d2d1e9b21f7df7a82dcbe5 \ No newline at end of file +8cd70960c5ddf0d0b2c40b8b6af4ce6b0277ffdaf04f33fcb33227d2b99ad515 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index b8471fea9f..431329579e 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -4235,20 +4235,30 @@ static int arListCommand(ShellState *p, ArCommand *pAr){ */ static int arExtractCommand(ShellState *p, ArCommand *pAr){ const char *zSql1 = - "SELECT name, writefile(name, " + "SELECT :1 || name, writefile(:1 || name, " "CASE WHEN (data AND sz>=0 AND sz!=length(data)) THEN uncompress(data) " " ELSE data END, " "mode) FROM sqlar"; - const char *zSql2 = "SELECT name, mtime FROM sqlar"; + const char *zSql2 = "SELECT :1 || name, mtime FROM sqlar"; struct timespec times[2]; sqlite3_stmt *pSql = 0; int rc = SQLITE_OK; + char *zDir = 0; + + if( pAr->zDir ){ + zDir = sqlite3_mprintf("%s/", pAr->zDir); + }else{ + zDir = sqlite3_mprintf(""); + } memset(times, 0, sizeof(times)); times[0].tv_sec = time(0); shellPrepare(p, &rc, zSql1, &pSql); + if( rc==SQLITE_OK ){ + sqlite3_bind_text(pSql, 1, zDir, -1, SQLITE_STATIC); + } while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ if( pAr->bVerbose ){ raw_printf(stdout, "%s\n", sqlite3_column_text(pSql, 0)); @@ -4257,6 +4267,9 @@ static int arExtractCommand(ShellState *p, ArCommand *pAr){ shellFinalize(&rc, pSql); shellPrepare(p, &rc, zSql2, &pSql); + if( rc==SQLITE_OK ){ + sqlite3_bind_text(pSql, 1, zDir, -1, SQLITE_STATIC); + } while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ const char *zPath = (const char*)sqlite3_column_text(pSql, 0); times[1].tv_sec = (time_t)sqlite3_column_int64(pSql, 1); @@ -4268,6 +4281,7 @@ static int arExtractCommand(ShellState *p, ArCommand *pAr){ } shellFinalize(&rc, pSql); + sqlite3_free(zDir); return rc; } diff --git a/test/shell8.test b/test/shell8.test index 4c412b41dc..2d2fc7b94d 100644 --- a/test/shell8.test +++ b/test/shell8.test @@ -34,12 +34,14 @@ proc populate_dir {dirname spec} { } } -proc dir_to_list {dirname} { +proc dir_to_list {dirname {n -1}} { + if {$n<0} {set n [llength [file split $dirname]]} + set res [list] foreach f [glob -nocomplain $dirname/*] { set mtime [file mtime $f] set perm [file attributes $f -perm] - set relpath [file join {*}[lrange [file split $f] 1 end]] + set relpath [file join {*}[lrange [file split $f] $n end]] lappend res if {[file isdirectory $f]} { lappend res [list $relpath / $mtime $perm] @@ -78,6 +80,13 @@ do_test 1.1 { dir_to_list ar1 } $expected +do_test 1.2 { + file delete -force ar3 + file mkdir ar3 + catchcmd test_ar.db ".ar xvC ar3" + dir_to_list ar3/ar1 +} $expected + finish_test