code wiki / _hdl_build / nx_figures_data_push.nx
nx_figures_data_push.nx source
↩ module page · 112 lines · 5152 B
1// nx_figures_data_push.nx -- push the 3 downloadable dataset files (figures_data.{csv,json,tsv}) to the
2// live wiki doc-root as STATIC ASSETS, so the <a href="/wiki/figures_data.csv" download> links on
3// /wiki/figures.html actually resolve. ADDITIVE: each push is `mkdir -p <wikidir>; cat > <wikidir>/<f>`
4// -- writes exactly that one file, never deletes/clobbers anything else.
5//
6// REUSE: the proven sovereign push spine _offc/nx_aw_push.elf (vault-backed SSH stream). We drive it in
7// its argv mode (argc>=3: src-spec-file + dst-cmd-file) with per-file spec files, so it never collides
8// with the default awpush.src/.dst the page publisher uses. Each nx_aw_push runs as a SEPARATE forked
9// process (its 4GB sys_read_file reservation lives in the child, not here) -- so pushing 3 files from
10// one parent is safe. license_tier: ORIGINAL
11import "nx_syscalls.nx"
12const FD_MAGIC_1024: i64 = 1024
13
14const FD_WIKIDIR: *u8 = "/volume1/homes/elderwesto/nishihost/sites/nishifamily/wiki" as *u8
15const FD_PUSH_ELF: *u8 = "_offc/nx_aw_push.elf" as *u8
16const FD_MODE_0644: i64 = 0x1a4
17
18func fd_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
19func fd_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != 0 as u8 { dst[o] = s[i]; o = o + 1; i = i + 1 } return o }
20
21// write a NUL-terminated string (known length) to a file (fresh).
22func fd_write_file(path: *u8, content: *u8, clen: i64) -> i64 {
23 let fd: i64 = sys_openat_wr(path, FD_MODE_0644)
24 if fd < 0 { return 0 - 1 }
25 sys_write(fd, content, clen)
26 sys_close(fd)
27 return 0
28}
29
30// fork+exec the push elf with argv = [elf, src_spec, dst_spec]; wait; return child exit code.
31func fd_run(src_spec: *u8, dst_spec: *u8) -> i64 {
32 let pid: i64 = sys_fork()
33 if pid == 0 {
34 let argv: *i64 = sys_mmap(64) as *i64
35 argv[0] = FD_PUSH_ELF as i64
36 argv[1] = src_spec as i64
37 argv[2] = dst_spec as i64
38 argv[3] = 0
39 let envp: *i64 = sys_mmap(16) as *i64
40 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
41 sys_execve(FD_PUSH_ELF, argv, envp)
42 sys_exit(127)
43 }
44 let st: *i64 = sys_mmap(16) as *i64
45 sys_wait4(pid, st, 0)
46 return (st[0] >> 8) & 0xff
47}
48
49// push web_assets/<fname> -> <wikidir>/<fname>. spec-file paths are tagged by idx so the 3 calls
50// don't share files. returns child exit code.
51func fd_push_one(fname: *u8, idx: i64) -> i64 {
52 // src spec file: contains the local path (web_assets/<fname>) + newline (aw_push trims it).
53 let srcspec: *u8 = sys_mmap(256)
54 var ss: i64 = 0
55 ss = fd_cat(srcspec, ss, "/tmp/figdata_src_" as *u8)
56 srcspec[ss] = (48 + idx) as u8; ss = ss + 1
57 srcspec[ss] = 0 as u8
58
59 let dstspec: *u8 = sys_mmap(256)
60 var ds: i64 = 0
61 ds = fd_cat(dstspec, ds, "/tmp/figdata_dst_" as *u8)
62 dstspec[ds] = (48 + idx) as u8; ds = ds + 1
63 dstspec[ds] = 0 as u8
64
65 // src content = web_assets/<fname>\n
66 let srcbuf: *u8 = sys_mmap(512)
67 var so: i64 = 0
68 so = fd_cat(srcbuf, so, "web_assets/" as *u8)
69 so = fd_cat(srcbuf, so, fname)
70 srcbuf[so] = 10 as u8; so = so + 1
71 srcbuf[so] = 0 as u8
72 if fd_write_file(srcspec, srcbuf, so) != 0 { fd_w(" src-spec write FAIL\n"); return 0 - 1 }
73
74 // dst content = mkdir -p <wikidir>; cat > <wikidir>/<fname>\n
75 let dstbuf: *u8 = sys_mmap(FD_MAGIC_1024)
76 var d: i64 = 0
77 d = fd_cat(dstbuf, d, "mkdir -p " as *u8)
78 d = fd_cat(dstbuf, d, FD_WIKIDIR)
79 d = fd_cat(dstbuf, d, "; cat > " as *u8)
80 d = fd_cat(dstbuf, d, FD_WIKIDIR)
81 d = fd_cat(dstbuf, d, "/" as *u8)
82 d = fd_cat(dstbuf, d, fname)
83 dstbuf[d] = 10 as u8; d = d + 1
84 dstbuf[d] = 0 as u8
85 if fd_write_file(dstspec, dstbuf, d) != 0 { fd_w(" dst-spec write FAIL\n"); return 0 - 1 }
86
87 fd_w(" pushing "); fd_w(fname); fd_w(" -> "); fd_w(FD_WIKIDIR); fd_w("/"); fd_w(fname); fd_w("\n")
88 let rc: i64 = fd_run(srcspec, dstspec)
89 fd_w(" push rc=");
90 let bb: *u8 = sys_mmap(28); var m: i64 = rc; let t: *u8 = sys_mmap(28); var k: i64 = 0
91 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
92 if m == 0 { t[0] = 48 as u8; k = 1 }
93 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
94 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); fd_w("\n")
95 return rc
96}
97
98func main() -> i64 {
99 fd_w("=== FIGURES DATA PUSH: 3 dataset files -> live wiki doc-root (additive static assets) ===\n")
100 var ok: i64 = 0
101 if fd_push_one("figures_data.csv" as *u8, 0) == 0 { ok = ok + 1 }
102 if fd_push_one("figures_data.json" as *u8, 1) == 0 { ok = ok + 1 }
103 if fd_push_one("figures_data.tsv" as *u8, 2) == 0 { ok = ok + 1 }
104 fd_w("=== pushed ");
105 let bb: *u8 = sys_mmap(28); var m: i64 = ok; var k: i64 = 0; let t: *u8 = sys_mmap(28)
106 if m == 0 { t[0] = 48 as u8; k = 1 }
107 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
108 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k)
109 fd_w("/3 data files LIVE ===\n")
110 if ok == 3 { sys_exit(0); return 0 }
111 sys_exit(1); return 1
112}