interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / patch / p2base.om

522 lines · 10077 bytes Raw Blame History
1note patch/p2base.om: the path builder, the byte sources and SHA-256 over them, file writes, the git
2note argument lists and the remover of a request's work folder.
3const PATMO long 20000000000
4note ---- path builder gpp (host words take the global directly)
5fn papc c uchar to void
6n = get gppl 0
7if lt n 4095
8put gpp n c
9put gppl 0 add n 1
10end
11end
12fn papt t view uchar * to void
13for i ulong len t bound 4096
14papc get t i
15end
16end
17note papb: gpp = <data>
18fn papb to void
19put gppl 0 0
20papt tfdata
21end
22note paprn: the repository's name (the public-list row fridx) appended to gpp
23fn paprn to void
24i = get fridx 0
25for k ulong get fanl i bound 128
26papc frnbyte i k
27end
28end
29note paprepo: gpp = <data>patches/<owner>/<repo>/
30fn paprepo to void
31papb
32papt tpsdir
33papt tfowner
34papc 47
35paprn
36papc 47
37end
38note papid t: gpp = <data>patches/<owner>/<repo>/<gpid>/<t>
39fn papid t view uchar * to void
40paprepo
41for k ulong 16
42papc get gpid k
43end
44papc 47
45papt t
46end
47note papnew t: gpp = <data>patches/<owner>/<repo>/.new-<gpstm>/<t>, this request's staging folder
48fn papnew t view uchar * to void
49paprepo
50papt tpnewd
51for k ulong 16
52papc get gpstm k
53end
54papc 47
55papt t
56end
57note papw t: gpp = <data>patch-work/pw<gpstm><t>, this request's work folder (t is empty or starts with /)
58fn papw t view uchar * to void
59papb
60papt tptmp
61papt tppw
62for k ulong 16
63papc get gpstm k
64end
65papt t
66end
67note papgs: gpp = <store>projects/<name>/repo.git, the repository's bare git store, built by the
68note store's own path builder (store/repos.om xspproj, as xsfolders does) in fpth and copied
69fn papgs to void
70xspproj get fridx 0
71fpt tfsrg
72put gppl 0 0
73for i ulong get fpthl 0 bound 4096
74papc get fpth i
75end
76end
77note paexist: the path in gpp exists
78fn paexist to bool
79r = stat gpp 0 get gppl 0 fstb 0 128
80ret ge r 0
81end
82note pamkdir: make the folder gpp (0700); true when it exists afterwards
83fn pamkdir to bool
84r = makedir gpp 0 get gppl 0 448
85if ge r 0
86ret true
87end
88ret paexist
89end
90note ---- byte sources. pasb w i: byte i of source w: 0 the mbox, 1 the statement, 2 the signature,
91note 3 the title, 4 the description, 5 the line buffer, 6 fxo, 7 title + line feed + description
92fn pasb w ulong i ulong to uchar
93if eq w 0
94ret get gpmb i
95end
96if eq w 1
97ret get gpst i
98end
99if eq w 2
100ret get gpsig i
101end
102if eq w 3
103ret get gpttl i
104end
105if eq w 4
106ret get gpdsc i
107end
108if eq w 5
109ret get gpln i
110end
111if eq w 6
112ret get fxo i
113end
114ret patd i
115end
116fn patd i ulong to uchar
117n = get gpttll 0
118if lt i n
119ret get gpttl i
120end
121if eq i n
122ret uchar 10
123end
124ret get gpdsc sub sub i n 1
125end
126note pahs w n o: o = SHA-256 of the first n bytes of source w
127fn pahs w ulong n ulong o edit uchar 32 to void
128c = new ulong 40 0
129b = new uchar 4096 0
130sha256_init c
131p = ulong 0
132while lt p n bound 16777216
133k = hmin sub n p 4096
134for i ulong k bound 4096
135put b i pasb w add p i
136end
137sha256_update c part b 0 k
138p = add p k
139end
140sha256_final c o
141end
142note ---- the line buffer gpln
143fn palb to void
144put gplnl 0 0
145end
146fn palc c uchar to void
147n = get gplnl 0
148if lt n 255
149put gpln n c
150put gplnl 0 add n 1
151end
152end
153fn paln v ulong to void
154d = new uchar 20 0
155k = sodec v d
156for i ulong k bound 20
157palc get d i
158end
159end
160note ---- files
161note pawall: all k bytes of b to fd
162fn pawall fd int b view uchar 4096 k ulong to bool
163q = ulong 0
164for it ulong 8192
165if ge q k
166ret true
167end
168r = write fd b q sub k q
169if le r 0
170if ne r -4
171ret false
172end
173else
174q = add q ulong r
175end
176end
177ret false
178end
179note pawf w n: create the file gpp (exclusive, 0600, no link followed) holding the first n bytes of
180note source w, written through to the disk before it is closed
181fn pawf w ulong n ulong to bool
182fd = fopen gpp 0 get gppl 0 557249 384
183if lt fd 0
184ret false
185end
186b = new uchar 4096 0
187p = ulong 0
188ok = true
189while lt p n bound 16777216
190k = hmin sub n p 4096
191for i ulong k bound 4096
192put b i pasb w add p i
193end
194if not pawall int fd b k
195ok = false
196break
197end
198p = add p k
199end
200if ok
201s = fsync int fd
202if lt s 0
203ok = false
204end
205end
206x = fclose int fd
207ret ok
208end
209note pawtxt t: the file gpp holding the text t
210fn pawtxt t view uchar * to bool
211palb
212for i ulong len t bound 255
213palc get t i
214end
215ret pawf 5 get gplnl 0
216end
217note ---- git argument lists (server/util.om fkb / fka / fkopen / fkc, run by fexec: no shell, empty
218note environment, standard input and error /dev/null)
219fn pakp to void
220for i ulong get gppl 0 bound 4096
221fkc get gpp i
222end
223end
224fn pakbase to void
225for i ulong 40
226fkc get gpbase i
227end
228end
229note pakst: argv = git --git-dir=<published store>/projects/<name>/repo.git
230fn pakst to void
231fkb
232fka tfgit
233fkopen
234fkt tfgitdir
235papgs
236pakp
237end
238fn pakc1 t view uchar * to void
239fka tpc
240fka t
241end
242note pakwt: argv = git -C <work folder>/w --attr-source=<empty tree> -c <setting> ... for every git run in
243note the throwaway work tree. The attribute source is the empty tree, so no .gitattributes file the
244note patch writes (nor the index's) changes what git reports or converts: binary tests, diff drivers,
245note textconv, filters and line endings all see no attributes.
246fn pakwt to void
247fkb
248fka tfgit
249fka tpdC
250fkopen
251papw tpww
252pakp
253fka tpatsrc
254pakc1 tpk1
255pakc1 tpk2
256pakc1 tpk3
257pakc1 tpk4
258pakc1 tpk5
259pakc1 tpk6
260pakc1 tpk7
261pakc1 tpk8
262pakc1 tpk9
263pakc1 tpk10
264pakc1 tpk11
265pakc1 tpk12
266pakc1 tpk13
267pakc1 tpk14
268pakc1 tpk15
269pakc1 tpk16
270end
271note ---- the work folder remover. git fills <data>patch-work/pw<stem>/ with the files and folders a patch
272note names, so nothing about their names, depth or kind is assumed. A forked child changes into the
273note folder and removes by relative name from the inside: a file, link or other entry is unlinked, an
274note empty folder removed, and a folder that is not empty is entered through a descriptor opened with
275note no-follow (a link is never entered) and emptied first. No path is built, so no path length or
276note depth limits it, and it only ever steps back up as often as it stepped down.
277fn parmnl o ulong to ulong
278k = ulong 0
279while lt k 256 bound 256
280if eq get gpde add o k 0
281ret k
282end
283k = add k 1
284end
285ret k
286end
287note parmdot: the entry name at o is . or ..
288fn parmdot o ulong nl ulong to bool
289if eq nl 1
290ret eq get gpde o 46
291end
292if eq nl 2
293if eq get gpde o 46
294ret eq get gpde add o 1 46
295end
296end
297ret false
298end
299note parment: remove the entry at o (type ty, 4 a folder): 1 removed, 2 entered it, 3 cannot
300fn parment o ulong nl ulong ty uchar to ulong
301r = long 0
302if ne ty 4
303r = unlink gpde o nl
304if ge r 0
305ret 1
306end
307if ne r -21
308ret 3
309end
310end
311r = rmdir gpde o nl
312if ge r 0
313ret 1
314end
315fd = fopen gpde o nl 573440 0
316if lt fd 0
317ret 3
318end
319r = fchdir int fd
320x = fclose int fd
321if lt r 0
322ret 3
323end
324ret 2
325end
326note parmscan: one pass over the folder open as fd: 0 it is empty, 1 entries were removed (scan again),
327note 2 entered a folder, 3 an entry could not be removed
328fn parmscan fd int to ulong
329seen = ulong 0
330for it ulong 1000000
331n = getdnts fd gpde 0 32768
332if le n 0
333break
334end
335p = ulong 0
336while lt p ulong n bound 32768
337rl = or ulong get gpde add p 16 shl ulong get gpde add p 17 8
338if eq rl 0
339ret 3
340end
341nl = parmnl add p 19
342if not parmdot add p 19 nl
343seen = add seen 1
344r = parment add p 19 nl get gpde add p 18
345if ge r 2
346ret r
347end
348end
349p = add p rl
350end
351end
352if gt seen 0
353ret 1
354end
355ret 0
356end
357note parmch: the child: empty the current folder and everything below it, then exit 0
358fn parmch to void
359dep = ulong 0
360for it ulong 4000000000
361fd = fopen tpdot 0 1 540672 0
362if lt fd 0
363exit 3
364end
365st = parmscan int fd
366x = fclose int fd
367if eq st 3
368exit 4
369end
370if eq st 2
371dep = add dep 1
372end
373if eq st 0
374if eq dep 0
375exit 0
376end
377r = chdir tpdd 0 2
378if lt r 0
379exit 5
380end
381dep = sub dep 1
382end
383end
384exit 6
385end
386note parmtree: remove this request's work folder and all it holds (30 s, then the child is killed)
387fn parmtree to bool
388papw part tpdot 0 0
389pid = fork
390if lt pid 0
391ret false
392end
393if eq pid 0
394r = chdir gpp 0 get gppl 0
395if lt r 0
396exit 2
397end
398parmch
399exit 0
400end
401dl = add long monons 30000000000
402st = freap int pid dl
403papw part tpdot 0 0
404q = rmdir gpp 0 get gppl 0
405ret and eq st 0 ge q 0
406end
407note ---- small files of an item (patch/p5imp.om): read without fxo, so a caller may keep a listing there
408note pards: the file gpp into gpln (its first 256 bytes); the bytes read (256: the file has at least
409note that many), or -errno
410fn pards to long
411put gplnl 0 0
412fd = fopen gpp 0 get gppl 0 524288 0
413if lt fd 0
414ret fd
415end
416for it ulong 64
417n = get gplnl 0
418if ge n 256
419break
420end
421r = read int fd gpln n sub 256 n
422if le r 0
423break
424end
425put gplnl 0 add n ulong r
426end
427x = fclose int fd
428ret long get gplnl 0
429end
430note pal40: gpln is 40 lowercase hex digits and a line feed
431fn pal40 to bool
432if ne get gplnl 0 41
433ret false
434end
435for i ulong 40
436if lt sohexv get gpln i 0
437ret false
438end
439end
440ret eq get gpln 40 10
441end
442note palnis t: gpln is exactly t
443fn palnis t view uchar * to bool
444if ne get gplnl 0 len t
445ret false
446end
447for i ulong len t bound 256
448if ne get gpln i get t i
449ret false
450end
451end
452ret true
453end
454note pastrd: the status file of item gpid: 0 "open\n", 1 "closed\n", 2 "merged\n", 9 anything else
455fn pastrd to ulong
456papid tpfss
457r = pards
458if palnis tpopen
459ret 0
460end
461if palnis tpsw1
462ret 1
463end
464if palnis tpsw2
465ret 2
466end
467ret 9
468end
469note pastsz: the size of the file paexist last found (st_size of struct stat, aarch64 offset 48)
470fn pastsz to ulong
471v = ulong 0
472for i ulong 8
473v = or v shl ulong get fstb add 48 i mul i 8
474end
475ret v
476end
477note ---- the bundle diff cache: <data>pdiff/<owner>/<repo>/<id> (derived data, safe to delete)
478note papdr: gpp = <data>pdiff/<owner>/<repo>/
479fn papdr to void
480papb
481papt tpdpd
482papt tfowner
483papc 47
484paprn
485papc 47
486end
487note papdf: gpp = the cache file of item gpid
488fn papdf to void
489papdr
490for k ulong 16
491papc get gpid k
492end
493end
494note papdfg: gpp = the marker beside it, <id>.big: an empty file that says the bundle diff of item gpid
495note was cut at 16 MiB (patch/p5imp.om pabbig)
496fn papdfg to void
497papdf
498papt tpsfxg
499end
500note papdfn: gpp = this request's staging file beside it, .new-<gpstm>
501fn papdfn to void
502papdr
503papt tpnewd
504for k ulong 16
505papc get gpstm k
506end
507end
508note pamkpd: make <data>pdiff/<owner>/<repo>/ (0700 each); false when it is not there afterwards
509fn pamkpd to bool
510papb
511papt tpdpd
512if not pamkdir
513ret false
514end
515papt tfowner
516if not pamkdir
517ret false
518end
519papc 47
520paprn
521ret pamkdir
522end