Improved error and help messages for the ".archive" command and "-A" option

to the CLI. If a memory leak in --list processing.

FossilOrigin-Name: 02541ac6f919a8a8b18ef0525c4ee24fdbc5c1883171fb1a492434cd0f006f7c
This commit is contained in:
drh
2018-05-17 14:09:06 +00:00
parent 1f22f62582
commit d0f9cdcc63
3 changed files with 30 additions and 23 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
C Fix\smemory\serrors\sassociated\swith\sargv\sin\sthe\sCLI\swhen\sit\sis\ncompiled\son\sWindows. C Improved\serror\sand\shelp\smessages\sfor\sthe\s".archive"\scommand\sand\s"-A"\soption\nto\sthe\sCLI.\sIf\sa\smemory\sleak\sin\s--list\sprocessing.
D 2018-05-17T13:29:14.965 D 2018-05-17T14:09:06.396
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in bfc40f350586923e0419d2ea4b559c37ec10ee4b6e210e08c14401f8e340f0da F Makefile.in bfc40f350586923e0419d2ea4b559c37ec10ee4b6e210e08c14401f8e340f0da
@@ -494,7 +494,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 6415381a0e9d22c0e7cba33ca4a53f81474190862f5d4838190f5eb5b0b47bc9 F src/resolve.c 6415381a0e9d22c0e7cba33ca4a53f81474190862f5d4838190f5eb5b0b47bc9
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c a35d462ee7a3c0856ad7a9d9c8921fbf3d91d911a8f39ad9d61302eb43b24a71 F src/select.c a35d462ee7a3c0856ad7a9d9c8921fbf3d91d911a8f39ad9d61302eb43b24a71
F src/shell.c.in e4086ed1af95dc9430e628e4dc9fadae91111d5f241fca11b68b8105896c5f2c F src/shell.c.in d9154a6b52ce772717894e4045a336eb7ceeab87dee1976273f4621c809c72ea
F src/sqlite.h.in 34be2d0d18bf4726538793bdc9854cd87f689fda4b3789515134cdbd68188cf4 F src/sqlite.h.in 34be2d0d18bf4726538793bdc9854cd87f689fda4b3789515134cdbd68188cf4
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 9887b27e69c01e79c2cbe74ef73bf01af5b5703d6a7f0a4371e386d7249cb1c7 F src/sqlite3ext.h 9887b27e69c01e79c2cbe74ef73bf01af5b5703d6a7f0a4371e386d7249cb1c7
@@ -1728,7 +1728,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P ed5b09680fd6659ebbe5ace3c1c56f3962bbd75cfdf65c7565651900cf87917a P 4474d69b5c21b4e6f0d1376fbceca0f18c715ff673aea63053a02bfbe041d03b
R 8f0e11b03bcaa4f31e83d13ec47c0763 R 835a789214eecbe14ece19d570e27697
U drh U drh
Z 09fcdd5831882bd1e0d99424cf0a518a Z 40bf372b75111f9f6f7fc064ea2d367d
+1 -1
View File
@@ -1 +1 @@
4474d69b5c21b4e6f0d1376fbceca0f18c715ff673aea63053a02bfbe041d03b 02541ac6f919a8a8b18ef0525c4ee24fdbc5c1883171fb1a492434cd0f006f7c
+23 -16
View File
@@ -4874,6 +4874,7 @@ struct ArCommand {
u8 bZip; /* True if the archive is a ZIP */ u8 bZip; /* True if the archive is a ZIP */
u8 bDryRun; /* True if --dry-run */ u8 bDryRun; /* True if --dry-run */
u8 bAppend; /* True if --append */ u8 bAppend; /* True if --append */
u8 fromCmdLine; /* Run from -A instead of .archive */
int nArg; /* Number of command arguments */ int nArg; /* Number of command arguments */
char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */ char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */
const char *zFile; /* --file argument, or NULL */ const char *zFile; /* --file argument, or NULL */
@@ -4920,13 +4921,18 @@ static int arUsage(FILE *f){
** Print an error message for the .ar command to stderr and return ** Print an error message for the .ar command to stderr and return
** SQLITE_ERROR. ** SQLITE_ERROR.
*/ */
static int arErrorMsg(const char *zFmt, ...){ static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){
va_list ap; va_list ap;
char *z; char *z;
va_start(ap, zFmt); va_start(ap, zFmt);
z = sqlite3_vmprintf(zFmt, ap); z = sqlite3_vmprintf(zFmt, ap);
va_end(ap); va_end(ap);
raw_printf(stderr, "Error: %s (try \".ar --help\")\n", z); utf8_printf(stderr, "Error: %s\n", z);
if( pAr->fromCmdLine ){
utf8_printf(stderr, "Use \"-A\" for more help\n");
}else{
utf8_printf(stderr, "Use \".archive --help\" for more help\n");
}
sqlite3_free(z); sqlite3_free(z);
return SQLITE_ERROR; return SQLITE_ERROR;
} }
@@ -4957,7 +4963,7 @@ static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
case AR_CMD_UPDATE: case AR_CMD_UPDATE:
case AR_CMD_HELP: case AR_CMD_HELP:
if( pAr->eCmd ){ if( pAr->eCmd ){
return arErrorMsg("multiple command options"); return arErrorMsg(pAr, "multiple command options");
} }
pAr->eCmd = eSwitch; pAr->eCmd = eSwitch;
break; break;
@@ -5017,8 +5023,6 @@ static int arParseCommand(
return arUsage(stderr); return arUsage(stderr);
}else{ }else{
char *z = azArg[1]; char *z = azArg[1];
memset(pAr, 0, sizeof(ArCommand));
if( z[0]!='-' ){ if( z[0]!='-' ){
/* Traditional style [tar] invocation */ /* Traditional style [tar] invocation */
int i; int i;
@@ -5030,11 +5034,11 @@ static int arParseCommand(
if( z[i]==pOpt->cShort ) break; if( z[i]==pOpt->cShort ) break;
} }
if( pOpt==pEnd ){ if( pOpt==pEnd ){
return arErrorMsg("unrecognized option: %c", z[i]); return arErrorMsg(pAr, "unrecognized option: %c", z[i]);
} }
if( pOpt->bArg ){ if( pOpt->bArg ){
if( iArg>=nArg ){ if( iArg>=nArg ){
return arErrorMsg("option requires an argument: %c",z[i]); return arErrorMsg(pAr, "option requires an argument: %c",z[i]);
} }
zArg = azArg[iArg++]; zArg = azArg[iArg++];
} }
@@ -5068,7 +5072,7 @@ static int arParseCommand(
if( z[i]==pOpt->cShort ) break; if( z[i]==pOpt->cShort ) break;
} }
if( pOpt==pEnd ){ if( pOpt==pEnd ){
return arErrorMsg("unrecognized option: %c\n", z[i]); return arErrorMsg(pAr, "unrecognized option: %c", z[i]);
} }
if( pOpt->bArg ){ if( pOpt->bArg ){
if( i<(n-1) ){ if( i<(n-1) ){
@@ -5076,7 +5080,7 @@ static int arParseCommand(
i = n; i = n;
}else{ }else{
if( iArg>=(nArg-1) ){ if( iArg>=(nArg-1) ){
return arErrorMsg("option requires an argument: %c\n",z[i]); return arErrorMsg(pAr, "option requires an argument: %c",z[i]);
} }
zArg = azArg[++iArg]; zArg = azArg[++iArg];
} }
@@ -5098,7 +5102,7 @@ static int arParseCommand(
const char *zLong = pOpt->zLong; const char *zLong = pOpt->zLong;
if( (n-2)<=strlen30(zLong) && 0==memcmp(&z[2], zLong, n-2) ){ if( (n-2)<=strlen30(zLong) && 0==memcmp(&z[2], zLong, n-2) ){
if( pMatch ){ if( pMatch ){
return arErrorMsg("ambiguous option: %s",z); return arErrorMsg(pAr, "ambiguous option: %s",z);
}else{ }else{
pMatch = pOpt; pMatch = pOpt;
} }
@@ -5106,11 +5110,11 @@ static int arParseCommand(
} }
if( pMatch==0 ){ if( pMatch==0 ){
return arErrorMsg("unrecognized option: %s", z); return arErrorMsg(pAr, "unrecognized option: %s", z);
} }
if( pMatch->bArg ){ if( pMatch->bArg ){
if( iArg>=(nArg-1) ){ if( iArg>=(nArg-1) ){
return arErrorMsg("option requires an argument: %s", z); return arErrorMsg(pAr, "option requires an argument: %s", z);
} }
zArg = azArg[++iArg]; zArg = azArg[++iArg];
} }
@@ -5239,6 +5243,7 @@ static int arListCommand(ArCommand *pAr){
} }
} }
shellFinalize(&rc, pSql); shellFinalize(&rc, pSql);
sqlite3_free(zWhere);
return rc; return rc;
} }
@@ -5441,12 +5446,14 @@ end_ar_transaction:
*/ */
static int arDotCommand( static int arDotCommand(
ShellState *pState, /* Current shell tool state */ ShellState *pState, /* Current shell tool state */
int fromCmdLine, /* True if -A command-line option, not .ar cmd */
char **azArg, /* Array of arguments passed to dot command */ char **azArg, /* Array of arguments passed to dot command */
int nArg /* Number of entries in azArg[] */ int nArg /* Number of entries in azArg[] */
){ ){
ArCommand cmd; ArCommand cmd;
int rc; int rc;
memset(&cmd, 0, sizeof(cmd)); memset(&cmd, 0, sizeof(cmd));
cmd.fromCmdLine = fromCmdLine;
rc = arParseCommand(azArg, nArg, &cmd); rc = arParseCommand(azArg, nArg, &cmd);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
int eDbType = SHELL_OPEN_UNSPEC; int eDbType = SHELL_OPEN_UNSPEC;
@@ -5493,7 +5500,7 @@ static int arDotCommand(
shellPutsFunc, 0, 0); shellPutsFunc, 0, 0);
} }
if( cmd.zSrcTable==0 && cmd.bZip==0 ){ if( cmd.zSrcTable==0 && cmd.bZip==0 && cmd.eCmd!=AR_CMD_HELP ){
if( cmd.eCmd!=AR_CMD_CREATE if( cmd.eCmd!=AR_CMD_CREATE
&& sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0) && sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0)
){ ){
@@ -5609,7 +5616,7 @@ static int do_meta_command(char *zLine, ShellState *p){
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){ if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
open_db(p, 0); open_db(p, 0);
rc = arDotCommand(p, azArg, nArg); rc = arDotCommand(p, 0, azArg, nArg);
}else }else
#endif #endif
@@ -8649,9 +8656,9 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
open_db(&data, 0); open_db(&data, 0);
if( z[2] ){ if( z[2] ){
argv[i] = &z[2]; argv[i] = &z[2];
arDotCommand(&data, argv+(i-1), argc-(i-1)); arDotCommand(&data, 1, argv+(i-1), argc-(i-1));
}else{ }else{
arDotCommand(&data, argv+i, argc-i); arDotCommand(&data, 1, argv+i, argc-i);
} }
readStdin = 0; readStdin = 0;
break; break;