vere: add -i and -o options for import and export

This commit is contained in:
Isaac Visintainer 2020-11-16 15:59:40 -08:00
parent 41ce22d6ae
commit 050bcf0ab9
4 changed files with 59 additions and 2 deletions

View File

@ -74,6 +74,7 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.abo = c3n;
u3_Host.ops_u.dem = c3n;
u3_Host.ops_u.dry = c3n;
u3_Host.ops_u.exp = c3n;
u3_Host.ops_u.gab = c3n;
u3_Host.ops_u.git = c3n;
@ -96,7 +97,7 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.kno_w = DefaultKernel;
while ( -1 != (ch_i=getopt(argc, argv,
"X:Y:G:J:B:K:A:H:I:C:w:u:e:F:k:n:p:r:LljacdgqstvxPDRS")) )
"X:Y:G:J:B:K:A:H:I:C:w:u:e:F:k:n:p:r:i:LljacdgoqstvxPDRS")) )
{
switch ( ch_i ) {
case 'X': {
@ -187,6 +188,10 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.roc_c = strdup(optarg);
break;
}
case 'i': {
u3_Host.ops_u.imp_c = strdup(optarg);
break;
}
case 'L': { u3_Host.ops_u.net = c3n; break; }
case 'l': { u3_Host.ops_u.lit = c3y; break; }
case 'j': { u3_Host.ops_u.tra = c3y; break; }
@ -194,6 +199,7 @@ _main_getopt(c3_i argc, c3_c** argv)
case 'c': { u3_Host.ops_u.nuu = c3y; break; }
case 'd': { u3_Host.ops_u.dem = c3y; break; }
case 'g': { u3_Host.ops_u.gab = c3y; break; }
case 'o': { u3_Host.ops_u.exp = c3y; break; }
case 'P': { u3_Host.ops_u.pro = c3y; break; }
case 'D': { u3_Host.ops_u.dry = c3y; break; }
case 'q': { u3_Host.ops_u.qui = c3y; break; }
@ -398,10 +404,12 @@ u3_ve_usage(c3_i argc, c3_c** argv)
"-e url Ethereum gateway\n",
"-F ship Fake keys; also disables networking\n",
"-g Set GC flag\n",
"-i jam_file import pier state\n",
"-j Create json trace file in .urb/put/trace\n",
"-K stage Start at Hoon kernel version stage\n",
"-k keys Private key file\n",
"-L local networking only\n",
"-o export pier state\n",
"-P Profiling\n",
"-p ames_port Set the ames port to bind to\n",
"-q Quiet\n",
@ -415,7 +423,7 @@ u3_ve_usage(c3_i argc, c3_c** argv)
"-w name Boot as ~name\n",
"-X path Scry, jam to file, then exit\n"
"-x Exit immediately\n",
"-Y file Optional name of jamfile (for -X)\n"
"-Y file Optional name of jamfile (for -X and -o)\n"
"\n",
"Development Usage:\n",
" To create a development ship, use a fakezod:\n",

View File

@ -265,6 +265,8 @@
c3_o gab; // -g, test garbage collection
c3_c* dns_c; // -H, ames bootstrap domain
c3_c* jin_c; // -I, inject raw event
c3_c* imp_c; // -i, import pier state
c3_o exp; // -o, export pier state
c3_w hap_w; // -C, cap memo cache
c3_c* lit_c; // -J, ivory (fastboot) kernel
c3_o tra; // -j, json trace

View File

@ -69,6 +69,32 @@ _fore_inject(u3_auto* car_u, c3_c* pax_c)
u3z(ovo);
}
/* _fore_import(): form an ovum from jammed archive at [pax_c] and inject it.
*/
static void
_fore_import(u3_auto* car_u, c3_c* pax_c)
{
// With apologies
u3_noun arc = u3ke_cue(u3m_file(pax_c));
c3_c * b64_c = u3r_string(u3do("crip", u3do("en-base64:mimes:html", arc)));
c3_w siz = strlen(b64_c) + 120;
c3_c bod_c[siz];
snprintf(bod_c, siz,
"{\"source\": {\"import-all\": {\"base64-jam\": \"%s\"}}, \
\"sink\": {\"stdout\": null}}", b64_c);
u3_noun dat = u3nt(u3_nul, u3i_word(strlen(bod_c)), u3i_string(bod_c));
u3_noun req = u3nt(c3n,
u3nc(u3i_string("ipv4"), u3i_word(0x7f000001)),
u3nq(u3i_string("POST"), u3i_string("/"), u3_nul, dat));
u3_noun wir = u3nc(u3i_string("http-server"), u3_nul);
u3_noun cad = u3nc(u3i_string("request-local"), req);
u3_auto_peer(
u3_auto_plan(car_u, u3_ovum_init(0, c3__e, wir, cad)),
0, 0, _fore_inject_bail);
}
/* _fore_io_talk():
*/
static void
@ -106,6 +132,10 @@ _fore_io_talk(u3_auto* car_u)
if ( u3_Host.ops_u.jin_c ) {
_fore_inject(car_u, u3_Host.ops_u.jin_c);
}
if ( u3_Host.ops_u.imp_c ) {
_fore_import(car_u, u3_Host.ops_u.imp_c);
}
}
/* _fore_io_kick(): handle no effects.

View File

@ -606,6 +606,23 @@ _pier_work_init(u3_pier* pir_u)
}
u3z(pex);
}
else if ( _(u3_Host.ops_u.exp) ) {
u3_noun pex = u3do("stab", u3i_string("/gx/lens/export-all/noun"));
u3_noun car;
u3_noun dek;
u3_noun pax;
u3r_trel(pex, &car, &dek, &pax);
if (!u3_Host.ops_u.puk_c) {
u3_Host.ops_u.puk_c = strdup("/archive");
}
// run the requested scry, jam to disk, then exit
//
u3l_log("pier: scry\n");
u3_pier_peek_last(pir_u, u3_nul, u3k(car), u3k(dek), u3k(pax),
pir_u, _pier_on_scry_done);
u3z(pex);
}
else {
// initialize i/o drivers
//