Fossil SCM

Two new sub-commands on "fossil system": "unzip" and "zip".

drh 2026-01-29 14:47 trunk
Commit 73e3217bc1ba40de2ab610179df09283e309c9cdd7920855dfa93dc93a93ec32
2 files changed +15 -11 +75
+15 -11
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -221,12 +221,14 @@
221221
helptext_vtab_register(db);
222222
builtin_vtab_register(db);
223223
g.repositoryOpen = 1;
224224
g.db = db;
225225
sqlite3_busy_timeout(db, 10000);
226
- sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
227
- db_maybe_set_encryption_key(db, g.zRepositoryName);
226
+ if( g.zRepositoryName ){
227
+ sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
228
+ db_maybe_set_encryption_key(db, g.zRepositoryName);
229
+ }
228230
if( g.zLocalDbName ){
229231
char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb' KEY ''",
230232
g.zLocalDbName);
231233
sqlite3_exec(db, zSql, 0, 0, 0);
232234
sqlite3_free(zSql);
@@ -240,19 +242,21 @@
240242
(void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
241243
/* Arrange to trace close operations so that static prepared statements
242244
** will get cleaned up when the shell closes the database connection */
243245
if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
244246
sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
245
- db_protect_only(PROTECT_NONE);
246
- sqlite3_set_authorizer(db, db_top_authorizer, db);
247
- if( local_bSqlCmdTest ){
248
- sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
249
- sqlcmd_db_protect, 0, 0);
250
- sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
251
- sqlcmd_db_protect_pop, 0, 0);
252
- sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
253
- sha1_shared_secret_sql_function, 0, 0);
247
+ if( g.zRepositoryName ){
248
+ db_protect_only(PROTECT_NONE);
249
+ sqlite3_set_authorizer(db, db_top_authorizer, db);
250
+ if( local_bSqlCmdTest ){
251
+ sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
252
+ sqlcmd_db_protect, 0, 0);
253
+ sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
254
+ sqlcmd_db_protect_pop, 0, 0);
255
+ sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
256
+ sha1_shared_secret_sql_function, 0, 0);
257
+ }
254258
}
255259
return SQLITE_OK;
256260
}
257261
258262
/*
259263
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -221,12 +221,14 @@
221 helptext_vtab_register(db);
222 builtin_vtab_register(db);
223 g.repositoryOpen = 1;
224 g.db = db;
225 sqlite3_busy_timeout(db, 10000);
226 sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
227 db_maybe_set_encryption_key(db, g.zRepositoryName);
 
 
228 if( g.zLocalDbName ){
229 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb' KEY ''",
230 g.zLocalDbName);
231 sqlite3_exec(db, zSql, 0, 0, 0);
232 sqlite3_free(zSql);
@@ -240,19 +242,21 @@
240 (void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
241 /* Arrange to trace close operations so that static prepared statements
242 ** will get cleaned up when the shell closes the database connection */
243 if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
244 sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
245 db_protect_only(PROTECT_NONE);
246 sqlite3_set_authorizer(db, db_top_authorizer, db);
247 if( local_bSqlCmdTest ){
248 sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
249 sqlcmd_db_protect, 0, 0);
250 sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
251 sqlcmd_db_protect_pop, 0, 0);
252 sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
253 sha1_shared_secret_sql_function, 0, 0);
 
 
254 }
255 return SQLITE_OK;
256 }
257
258 /*
259
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -221,12 +221,14 @@
221 helptext_vtab_register(db);
222 builtin_vtab_register(db);
223 g.repositoryOpen = 1;
224 g.db = db;
225 sqlite3_busy_timeout(db, 10000);
226 if( g.zRepositoryName ){
227 sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
228 db_maybe_set_encryption_key(db, g.zRepositoryName);
229 }
230 if( g.zLocalDbName ){
231 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb' KEY ''",
232 g.zLocalDbName);
233 sqlite3_exec(db, zSql, 0, 0, 0);
234 sqlite3_free(zSql);
@@ -240,19 +242,21 @@
242 (void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
243 /* Arrange to trace close operations so that static prepared statements
244 ** will get cleaned up when the shell closes the database connection */
245 if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
246 sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
247 if( g.zRepositoryName ){
248 db_protect_only(PROTECT_NONE);
249 sqlite3_set_authorizer(db, db_top_authorizer, db);
250 if( local_bSqlCmdTest ){
251 sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
252 sqlcmd_db_protect, 0, 0);
253 sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
254 sqlcmd_db_protect_pop, 0, 0);
255 sqlite3_create_function(db, "shared_secret", 2, SQLITE_UTF8, 0,
256 sha1_shared_secret_sql_function, 0, 0);
257 }
258 }
259 return SQLITE_OK;
260 }
261
262 /*
263
--- src/xsystem.c
+++ src/xsystem.c
@@ -442,10 +442,76 @@
442442
}
443443
}
444444
sqlite3_finalize(pStmt);
445445
sqlite3_close(db);
446446
}
447
+
448
+/*
449
+** unzip [-l] ZIPFILE
450
+*/
451
+void xsystem_unzip(int argc, char **argv){
452
+ const char *zZipfile = 0;
453
+ int doList = 0;
454
+ int i;
455
+ char *a[5];
456
+ int n;
457
+ extern int sqlite3_shell(int, char**);
458
+
459
+ for(i=1; i<argc; i++){
460
+ const char *z = argv[i];
461
+ if( z[0]=='-' ){
462
+ if( z[1]=='-' && z[2]!=0 ) z++;
463
+ if( strcmp(z,"-l")==0 ){
464
+ doList = 1;
465
+ }else
466
+ {
467
+ fossil_fatal("unknown option: %s", argv[i]);
468
+ }
469
+ }else if( zZipfile!=0 ){
470
+ fossil_fatal("extra argument: %s", z);
471
+ }else{
472
+ zZipfile = z;
473
+ }
474
+ }
475
+ if( zZipfile==0 ){
476
+ fossil_fatal("Usage: fossil sys unzip [-l] ZIPFILE");
477
+ }else if( file_size(zZipfile, ExtFILE)<0 ){
478
+ fossil_fatal("No such file: %s\n", zZipfile);
479
+ }
480
+ g.zRepositoryName = 0;
481
+ g.zLocalDbName = 0;
482
+ g.zConfigDbName = 0;
483
+ sqlite3_shutdown();
484
+ a[0] = argv[0];
485
+ a[1] = (char*)zZipfile;
486
+ if( doList ){
487
+ a[2] = ".mode column";
488
+ a[3] = "SELECT sz AS Size, date(mtime,'unixepoch') AS Date,"
489
+ " time(mtime,'unixepoch') AS Time, name AS Name"
490
+ " FROM zip;";
491
+ n = 4;
492
+ }else{
493
+ a[2] = ".mode list";
494
+ a[3] = "SELECT if(writefile(name,data,mode,mtime) IS NULL,"
495
+ "'error: '||name,'extracting: '||name) FROM zip;";
496
+ n = 4;
497
+ }
498
+ a[n] = 0;
499
+ sqlite3_shell(n,a);
500
+}
501
+
502
+/*
503
+** zip [OPTIONS] ZIPFILE FILE ...
504
+*/
505
+void xsystem_zip(int argc, char **argv){
506
+ int i;
507
+ for(i=0; i<argc; i++){
508
+ g.argv[i+1] = argv[i];
509
+ }
510
+ g.argc = argc+1;
511
+ filezip_cmd();
512
+}
447513
448514
/*
449515
** Available system commands.
450516
*/
451517
typedef struct XSysCmd XSysCmd;
@@ -476,17 +542,26 @@
476542
"Show the Present Working Directory name\n"
477543
},
478544
{ "stty", xsystem_stty,
479545
"\n"
480546
"Show the size of the TTY\n"
547
+ },
548
+ { "unzip", xsystem_unzip,
549
+ "[-l] ZIPFILE\n\n"
550
+ "Extract content from ZIPFILE, or list the content if the -l option\n"
551
+ "is used.\n"
481552
},
482553
{ "which", xsystem_which,
483554
"EXE ...\n"
484555
"Show the location on PATH of executables EXE\n"
485556
"Options:\n"
486557
" -a Show all path locations rather than just the first\n"
487558
},
559
+ { "zip", xsystem_zip,
560
+ "ZIPFILE FILE ...\n\n"
561
+ "Create a new ZIP archive named ZIPFILE using listed files as content\n"
562
+ },
488563
};
489564
490565
/*
491566
** COMMAND: system
492567
**
493568
--- src/xsystem.c
+++ src/xsystem.c
@@ -442,10 +442,76 @@
442 }
443 }
444 sqlite3_finalize(pStmt);
445 sqlite3_close(db);
446 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
448 /*
449 ** Available system commands.
450 */
451 typedef struct XSysCmd XSysCmd;
@@ -476,17 +542,26 @@
476 "Show the Present Working Directory name\n"
477 },
478 { "stty", xsystem_stty,
479 "\n"
480 "Show the size of the TTY\n"
 
 
 
 
 
481 },
482 { "which", xsystem_which,
483 "EXE ...\n"
484 "Show the location on PATH of executables EXE\n"
485 "Options:\n"
486 " -a Show all path locations rather than just the first\n"
487 },
 
 
 
 
488 };
489
490 /*
491 ** COMMAND: system
492 **
493
--- src/xsystem.c
+++ src/xsystem.c
@@ -442,10 +442,76 @@
442 }
443 }
444 sqlite3_finalize(pStmt);
445 sqlite3_close(db);
446 }
447
448 /*
449 ** unzip [-l] ZIPFILE
450 */
451 void xsystem_unzip(int argc, char **argv){
452 const char *zZipfile = 0;
453 int doList = 0;
454 int i;
455 char *a[5];
456 int n;
457 extern int sqlite3_shell(int, char**);
458
459 for(i=1; i<argc; i++){
460 const char *z = argv[i];
461 if( z[0]=='-' ){
462 if( z[1]=='-' && z[2]!=0 ) z++;
463 if( strcmp(z,"-l")==0 ){
464 doList = 1;
465 }else
466 {
467 fossil_fatal("unknown option: %s", argv[i]);
468 }
469 }else if( zZipfile!=0 ){
470 fossil_fatal("extra argument: %s", z);
471 }else{
472 zZipfile = z;
473 }
474 }
475 if( zZipfile==0 ){
476 fossil_fatal("Usage: fossil sys unzip [-l] ZIPFILE");
477 }else if( file_size(zZipfile, ExtFILE)<0 ){
478 fossil_fatal("No such file: %s\n", zZipfile);
479 }
480 g.zRepositoryName = 0;
481 g.zLocalDbName = 0;
482 g.zConfigDbName = 0;
483 sqlite3_shutdown();
484 a[0] = argv[0];
485 a[1] = (char*)zZipfile;
486 if( doList ){
487 a[2] = ".mode column";
488 a[3] = "SELECT sz AS Size, date(mtime,'unixepoch') AS Date,"
489 " time(mtime,'unixepoch') AS Time, name AS Name"
490 " FROM zip;";
491 n = 4;
492 }else{
493 a[2] = ".mode list";
494 a[3] = "SELECT if(writefile(name,data,mode,mtime) IS NULL,"
495 "'error: '||name,'extracting: '||name) FROM zip;";
496 n = 4;
497 }
498 a[n] = 0;
499 sqlite3_shell(n,a);
500 }
501
502 /*
503 ** zip [OPTIONS] ZIPFILE FILE ...
504 */
505 void xsystem_zip(int argc, char **argv){
506 int i;
507 for(i=0; i<argc; i++){
508 g.argv[i+1] = argv[i];
509 }
510 g.argc = argc+1;
511 filezip_cmd();
512 }
513
514 /*
515 ** Available system commands.
516 */
517 typedef struct XSysCmd XSysCmd;
@@ -476,17 +542,26 @@
542 "Show the Present Working Directory name\n"
543 },
544 { "stty", xsystem_stty,
545 "\n"
546 "Show the size of the TTY\n"
547 },
548 { "unzip", xsystem_unzip,
549 "[-l] ZIPFILE\n\n"
550 "Extract content from ZIPFILE, or list the content if the -l option\n"
551 "is used.\n"
552 },
553 { "which", xsystem_which,
554 "EXE ...\n"
555 "Show the location on PATH of executables EXE\n"
556 "Options:\n"
557 " -a Show all path locations rather than just the first\n"
558 },
559 { "zip", xsystem_zip,
560 "ZIPFILE FILE ...\n\n"
561 "Create a new ZIP archive named ZIPFILE using listed files as content\n"
562 },
563 };
564
565 /*
566 ** COMMAND: system
567 **
568

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button