interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / patch / p4take.om

1179 lines · 20408 bytes Raw Blame History
1note patch/p4take.om: POST /<owner>/<repo>/patches/new. The checks in order, each refusal one line
2note of text with nothing kept: session and CSRF (pagate); the repo field and the repository's git
3note store; base a commit reachable from the default branch the public list names; sizes and shapes
4note of title, description, mbox and sig; the signature by the session's key over the statement; then
5note the mbox is applied once on base in a throwaway work tree and, only if that is clean (no file is
6note binary, by git's marks and by the bytes of the applied diff, and no submodule is added), stored.
7note ---- the mbox scan
8note pamln s e t: the line gpmb[s, e) starts with t
9fn pamln s ulong e ulong t view uchar * to bool
10if lt sub e s len t
11ret false
12end
13for i ulong len t bound 64
14if ne get gpmb add s i get t i
15ret false
16end
17end
18ret true
19end
20note pafrom: the line is "From <40 lowercase hex> Mon Sep 17 00:00:00 2001", format-patch's first
21note line of every commit
22fn pafrom s ulong e ulong to bool
23if ne sub e s 70
24ret false
25end
26if not pamln s e tpfrom
27ret false
28end
29for i ulong 40
30if lt sohexv get gpmb add add s 5 i 0
31ret false
32end
33end
34ret pamln add s 45 e tpfrom2
35end
36fn paeol s ulong n ulong to ulong
37j = s
38while lt j n bound 4194304
39if eq get gpmb j 10
40ret j
41end
42j = add j 1
43end
44ret n
45end
46note padd: gpmb[j] and gpmb[j+1] are both a dot, inside [s, e)
47fn padd j ulong e ulong to bool
48if ge add j 1 e
49ret false
50end
51if ne get gpmb j 46
52ret false
53end
54ret eq get gpmb add j 1 46
55end
56note pasep: the byte bounds a path segment (/, space, quote)
57fn pasep c uchar to bool
58ret or or eq c 47 eq c 32 eq c 34
59end
60note paddseg j s e: the ".." at gpmb[j] is a whole segment of the path part gpmb[s, e): the byte
61note before it (when there is one) and the byte after it (when there is one) each bound a segment
62fn paddseg j ulong s ulong e ulong to bool
63if gt j s
64if not pasep get gpmb sub j 1
65ret false
66end
67end
68if lt add j 2 e
69ret pasep get gpmb add j 2
70end
71ret true
72end
73note paout s e: the path part gpmb[s, e) of a diff header names a way out of the repository: a ".."
74note segment, an empty segment (//) or a leading /
75fn paout s ulong e ulong to bool
76if ge s e
77ret false
78end
79if eq get gpmb s 47
80ret true
81end
82j = s
83while lt j e bound 4194304
84if padd j e
85if paddseg j s e
86ret true
87end
88end
89if eq get gpmb j 47
90if lt add j 1 e
91if eq get gpmb add j 1 47
92ret true
93end
94end
95end
96j = add j 1
97end
98ret false
99end
100note padiffl: a line of a diff: 2 a binary patch, 3 a header naming a path outside, else 0
101fn padiffl s ulong e ulong to ulong
102if pamln s e tpgbp
103if eq sub e s len tpgbp
104ret 2
105end
106end
107if pamln s e tpbf
108ret 2
109end
110if pamln s e tprnf
111if paout add s len tprnf e
112ret 3
113end
114end
115if pamln s e tprnt
116if paout add s len tprnt e
117ret 3
118end
119end
120ret 0
121end
122note pascan: one pass over the lines of the mbox. gpncm = commits (From lines); gpgrd = 2 for a
123note binary patch or 3 for an outside path, otherwise 0. False when the first line
124note is not a From line: not format-patch output.
125fn pascan to bool
126n = get gpmbl 0
127put gpncm 0 0
128put gpgrd 0 0
129s = ulong 0
130ind = false
131for it ulong 4194304
132if ge s n
133break
134end
135e = paeol s n
136if pafrom s e
137put gpncm 0 add get gpncm 0 1
138ind = false
139else
140if eq s 0
141ret false
142end
143g = ulong 0
144if pamln s e tpdg
145ind = true
146if paout add s len tpdg e
147g = 3
148end
149else
150if ind
151g = padiffl s e
152end
153end
154if and ne g 0 eq get gpgrd 0 0
155put gpgrd 0 g
156end
157end
158s = add e 1
159end
160ret gt get gpncm 0 0
161end
162note ---- base
163note pabasec: 0 base is a commit on the main branch; else the refusal's status with its text written
164fn pabasec to long
165fkgit
166fka tpcatf
167fka tpde
168fkopen
169pakbase
170fkt tpcmt
171r = fexec PATMO
172if lt r 0
173ret parefu 500 tpmint
174end
175if ne r 0
176ret parefu 422 tpmunk
177end
178fkgit
179fka tpgmb
180fka tpisa
181fkopen
182pakbase
183fkopen
184fkt tprh
185i = get fridx 0
186o = get fabo i
187for k ulong get fabl i bound 64
188fkc get fabr add o k
189end
190r = fexec PATMO
191if eq r 0
192ret 0
193end
194if eq r 1
195ret parefu 422 tpmnotm
196end
197ret parefu 500 tpmint
198end
199note ---- the statement and the id
200fn pastc c uchar to void
201n = get gpstl 0
202if lt n 511
203put gpst n c
204put gpstl 0 add n 1
205end
206end
207fn pasthex h view uchar 32 to void
208x = new uchar 64 0
209sohex h x
210for i ulong 64
211pastc get x i
212end
213pastc 10
214end
215note pastmt: gpst = "interplane-patch 1\n<owner>/<repo>\n<base>\n<sha256 of the mbox>\n<sha256 of
216note title, line feed, description>\n", all hex lowercase; gpid = the first 16 hex of its SHA-256
217fn pastmt to void
218put gpstl 0 0
219for i ulong len tpst1
220pastc get tpst1 i
221end
222for i ulong len tfowner
223pastc get tfowner i
224end
225pastc 47
226r = get fridx 0
227for k ulong get fanl r bound 128
228pastc frnbyte r k
229end
230pastc 10
231for i ulong 40
232pastc get gpbase i
233end
234pastc 10
235h = new uchar 32 0
236pahs 0 get gpmbl 0 h
237pasthex h
238pahs 7 add add get gpttll 0 1 get gpdscl 0 h
239pasthex h
240pahs 1 get gpstl 0 h
241x = new uchar 64 0
242sohex h x
243for i ulong 16
244put gpid i get x i
245end
246end
247note ---- the signature: ssh-keygen -Y verify -f <allowed signers> -I forge-user -n interplane-patch
248note -s <signature> with the statement on standard input (the argv exec and temp files of the
249note sign-in check, social/20crypt.om and 40auth.om). The one allowed signer is the session's key.
250note paspk: the ed25519 key of the session's did:key into pk
251fn paspk pk edit uchar 32 to bool
252d = get gscur 0
253o = get gsso d
254l = get gssl d
255w = len tsdidp
256if or le l w gt sub l w 64
257ret false
258end
259z = new uchar 64 0
260for i ulong sub l w bound 64
261put z i get gsstr add add o w i
262end
263ret sodidpk part z 0 sub l w pk
264end
265note pasigw: the three temp files: a allowed signers, s signature, m statement
266fn pasigw pk view uchar 32 to bool
267al = new uchar 128 0
268k = sopkline pk al
269if not sotmpw 97 part al 0 k
270ret false
271end
272sg = new uchar 4096 0
273n = get gpsigl 0
274for i ulong n bound 4096
275put sg i get gpsig i
276end
277if not sotmpw 115 part sg 0 n
278ret false
279end
280m = new uchar 512 0
281n = get gpstl 0
282for i ulong n bound 512
283put m i get gpst i
284end
285ret sotmpw 109 part m 0 n
286end
287fn pasigrun to long
288sotmpp 109
289mfd = fopen gspth 0 get gspthl 0 524288 0
290if lt mfd 0
291ret -500
292end
293soavb
294soava tssshkg
295soava tsY
296soava tsverify
297soava tsdf
298sotmpp 97
299soavpth
300soava tsdI
301soava tsprinc
302soava tsdn
303soava tpns
304soava tsds
305sotmpp 115
306soavpth
307r = sorunv mfd 5000
308x = fclose int mfd
309if eq r -2
310ret -500
311end
312if eq r -1
313ret -500
314end
315ret r
316end
317note pasigck: 0 the signature verifies; else the refusal's status with its text written
318fn pasigck to long
319if not sovlim
320ret parefu 429 tpmrate
321end
322pk = new uchar 32 0
323if not paspk pk
324ret parefu 500 tpmint
325end
326st = new uchar 8 0
327if not sorand st
328ret parefu 500 tpmint
329end
330for i ulong 8
331put gsstem i get st i
332end
333r = long -500
334if pasigw pk
335r = pasigrun
336end
337sotmprm 97
338sotmprm 115
339sotmprm 109
340if eq r 0
341ret 0
342end
343if lt r 0
344ret parefu 500 tpmint
345end
346ret parefu 403 tpmsig
347end
348note ---- apply once on base in a throwaway work tree
349note pastem: gpstm = 16 random hex digits naming this request's work and staging folders
350fn pastem to bool
351r = new uchar 8 0
352if not sorand r
353ret false
354end
355x = new uchar 16 0
356sohex r x
357for i ulong 16
358put gpstm i get x i
359end
360ret true
361end
362note pawinit: make <data>patch-work/pw<stem>/ with an empty git repository w whose objects are borrowed from
363note the repository's store (objects/info/alternates): the store is only read, and nothing the work
364note folder makes is ever written into it (the intake's pawork, and the bundle diff of patch/p5imp.om)
365fn pawinit to bool
366papb
367papt tptmp
368x = pamkdir
369papw part tpdot 0 0
370r = makedir gpp 0 get gppl 0 448
371if lt r 0
372ret false
373end
374fkb
375fka tfgit
376pakc1 tpk17
377fka tpinit
378fka tpq
379fka tptpl
380fkopen
381papw tpww
382pakp
383r = fexec PATMO
384if ne r 0
385ret false
386end
387palb
388papgs
389if gt get gppl 0 240
390ret false
391end
392for i ulong get gppl 0 bound 240
393palc get gpp i
394end
395for i ulong len tpobj
396palc get tpobj i
397end
398papw tpwalt
399ret pawf 5 get gplnl 0
400end
401note pawork: the work folder of pawinit with the mbox as m
402fn pawork to bool
403if not pawinit
404ret false
405end
406papw tpwm
407ret pawf 0 get gpmbl 0
408end
409note pasteq: the stored statement of item gpid is byte-equal to this request's gpst[0, gpstl)
410fn pasteq to bool
411pafp tpfst
412n = frdall
413if ne n long get gpstl 0
414ret false
415end
416for i ulong get gpstl 0 bound 512
417if ne get fxo i get gpst i
418ret false
419end
420end
421ret true
422end
423note pahex40: fxo[0, 40) is 40 lowercase hex digits followed by a line feed; copied into gphead
424fn pahex40 to bool
425if ne get fxol 0 41
426ret false
427end
428for i ulong 40
429c = get fxo i
430if lt sohexv c 0
431ret false
432end
433put gphead i c
434end
435ret eq get fxo 40 10
436end
437note panum: the decimal number in fxo[0, n) before its line feed, 999999999 when it is not one
438fn panum to ulong
439n = get fxol 0
440if or lt n 2 gt n 10
441ret 999999999
442end
443v = ulong 0
444for i ulong sub n 1 bound 16
445c = get fxo i
446if not fisdig c
447ret 999999999
448end
449v = add mul v 10 ulong sub c 48
450end
451ret v
452end
453note pabinat s: fxo[s, s+4) is "-\t-\t" (the caller keeps s+4 inside the output)
454fn pabinat s ulong to bool
455a = and eq get fxo s 45 eq get fxo add s 1 9
456b = and eq get fxo add s 2 45 eq get fxo add s 3 9
457ret and a b
458end
459note pabinns: fxo holds `git diff --numstat --no-renames`: a line starts with "-\t-\t", git's mark of
460note a binary file. The mbox scan (padiffl) sees only the bytes as sent; git am decodes a mail body
461note sent base64 or quoted-printable first, so only git's own view after the apply covers every way in.
462fn pabinns to bool
463n = get fxol 0
464s = ulong 0
465for it ulong 16777216
466if ge s n
467break
468end
469if le add s 4 n
470if pabinat s
471ret true
472end
473end
474e = s
475while lt e n bound 16777216
476if eq get fxo e 10
477break
478end
479e = add e 1
480end
481s = add e 1
482end
483ret false
484end
485note pafxln s e t: the line fxo[s, e) starts with t
486fn pafxln s ulong e ulong t view uchar * to bool
487if lt sub e s len t
488ret false
489end
490for i ulong len t bound 64
491if ne get fxo add s i get t i
492ret false
493end
494end
495ret true
496end
497note Read the same normalized diff as Git, before applying any of the mail messages.
498text tpmspl "mailsplit"
499text tpmio "mailinfo"
500text tpmd "/mails"
501text tpmslash "/mails/"
502text tpmsg "/mails/message"
503text tpmpt "/mails/patch"
504text tpmo "-o"
505text tpmdig "-d4"
506fn pamaid num ulong to void
507papw tpmslash
508d = ulong 1000
509for i ulong 4
510papc uchar add rem div num d 10 48
511d = div d 10
512end
513end
514fn pafxcpy to bool
515n = get fxol 0
516s = ulong 0
517header = false
518while lt s n bound 16777216
519e = s
520while lt e n bound 16777216
521if eq get fxo e 10
522break
523end
524e = add e 1
525end
526if pafxln s e tpdg
527header = true
528end
529if and header or pafxln s e tpcpf pafxln s e tpcpt
530ret true
531end
532s = add e 1
533end
534ret false
535end
536fn pamread idx ulong tmo long to long
537pamaid idx
538fd = fopen gpp 0 get gppl 0 524288 0
539if lt fd 0
540ret 500
541end
542pakwt
543fka tpmio
544fkopen
545papw tpmsg
546pakp
547fkopen
548papw tpmpt
549pakp
550r = fexecin tmo int fd
551x = fclose int fd
552if ne r 0
553ret 422
554end
555papw tpmpt
556fpb
557for i ulong get gppl 0 bound 4096
558fpc get gpp i
559end
560r = frdall
561if or lt r 0 ne get fxotr 0 0
562ret 422
563end
564put fxol 0 ulong r
565if pafxcpy
566ret 409
567end
568ret 0
569end
570fn pamail to long
571papw tpmd
572if not pamkdir
573ret parefu 500 tpmint
574end
575dl = add long monons PATMO
576pakwt
577fka tpmspl
578fka tpmdig
579fkopen
580fkt tpmo
581papw tpmd
582pakp
583fkopen
584papw tpwm
585pakp
586r = fexec PATMO
587if or ne r 0 ne get fxotr 0 0
588ret parefu 422 tpmappl
589end
590n = panum
591if or ne n get gpncm 0 gt n 100
592ret parefu 422 tpmcnt
593end
594for i ulong n bound 100
595left = sub dl long monons
596if le left 0
597ret parefu 422 tpmappl
598end
599r = pamread add i 1 left
600if eq r 409
601ret parefu 422 tpmcopy
602end
603if ne r 0
604ret parefu 422 tpmappl
605end
606end
607ret 0
608end
609note pabinfx: the bytes of the full diff fxo[0, fxol) (paapply3's last git run) hold a NUL byte, a line
610note that is exactly "GIT binary patch" or a line that starts "Binary files ". Every line of a diff's
611note body starts with a space, + or -, so those two at column 0 are git's own markers. The bytes decide:
612note git's own binary test reads only a file's first 8000 bytes (pabinns cannot see a later NUL).
613fn pabinfx to bool
614n = get fxol 0
615s = ulong 0
616for it ulong 16777216
617if ge s n
618break
619end
620e = s
621while lt e n bound 16777216
622c = get fxo e
623if eq c 0
624ret true
625end
626if eq c 10
627break
628end
629e = add e 1
630end
631if pafxln s e tpbf
632ret true
633end
634if eq sub e s len tpgbp
635if pafxln s e tpgbp
636ret true
637end
638end
639s = add e 1
640end
641ret false
642end
643note paraw: fxo holds `git diff --raw --no-renames`: gpnfl = its lines (files changed); false when a
644note line's new mode is 160000 (a submodule) or a line is not a raw line
645fn paraw to bool
646n = get fxol 0
647c = ulong 0
648s = ulong 0
649for it ulong 16777216
650if ge s n
651break
652end
653if gt add s 14 n
654ret false
655end
656if ne get fxo s 58
657ret false
658end
659if pasubm add s 8
660ret false
661end
662c = add c 1
663e = s
664while lt e n bound 16777216
665if eq get fxo e 10
666break
667end
668e = add e 1
669end
670s = add e 1
671end
672put gpnfl 0 c
673ret true
674end
675note pasubm: fxo[p, p+6) is the mode 160000
676fn pasubm p ulong to bool
677if ne get fxo p 49
678ret false
679end
680if ne get fxo add p 1 54
681ret false
682end
683for i ulong 4
684if ne get fxo add add p 2 i 48
685ret false
686end
687end
688ret true
689end
690note pakrange: one argument "<base>..HEAD"
691fn pakrange to void
692fkopen
693pakbase
694fkt tpdots
695fkt tphead
696end
697note paapply2: the git runs in the work tree: read-tree base, HEAD at base, am, then head, commit
698note count, raw diff (files, submodules), numstat (binary files) and the full diff left in fxo, whose
699note bytes are checked too (pabinfx). 0, or the refusal's status.
700fn paapply2 to long
701pakwt
702fka tprdt
703fkopen
704pakbase
705r = fexec PATMO
706if ne r 0
707ret parefu 500 tpmint
708end
709pakwt
710fka tpupr
711fka tpnod
712fka tphead
713fkopen
714pakbase
715r = fexec PATMO
716if ne r 0
717ret parefu 500 tpmint
718end
719pakwt
720fka tpam
721fka tpqq
722fka tpamd
723fka tpamk
724fka tpamn
725fka tpam3
726fkopen
727papw tpwm
728pakp
729r = fexec PATMO
730if ne r 0
731ret parefu 422 tpmappl
732end
733pakwt
734fka tprevp
735fka tphead
736r = fexec PATMO
737if ne r 0
738ret parefu 500 tpmint
739end
740if not pahex40
741ret parefu 500 tpmint
742end
743pakwt
744fka tprevl
745fka tpcnt
746pakrange
747r = fexec PATMO
748if ne r 0
749ret parefu 500 tpmint
750end
751if ne panum get gpncm 0
752ret parefu 422 tpmcnt
753end
754ret paapply3
755end
756fn paapply3 to long
757pakwt
758fka tpdiff
759fka tpnoext
760fka tpnotc
761fka tpraw
762fka tpnorn
763fkopen
764pakbase
765fka tphead
766r = fexec PATMO
767if or ne r 0 ne get fxotr 0 0
768ret parefu 500 tpmint
769end
770if not paraw
771ret parefu 422 tpmsub
772end
773pakwt
774fka tpdiff
775fka tpnoext
776fka tpnotc
777fka tpnumst
778fka tpnorn
779fkopen
780pakbase
781fka tphead
782r = fexec PATMO
783if or ne r 0 ne get fxotr 0 0
784ret parefu 500 tpmint
785end
786if pabinns
787ret parefu 422 tpmbin
788end
789pakwt
790fka tpdiff
791fka tpnoext
792fka tpnotc
793fka tpfull
794fka tpdM
795fkopen
796pakbase
797fka tphead
798r = fexec PATMO
799if ne r 0
800ret parefu 500 tpmint
801end
802if ne get fxotr 0 0
803ret parefu 413 tpmdbig
804end
805if pabinfx
806ret parefu 422 tpmbin
807end
808ret 0
809end
810note ---- the store: <data>patches/<owner>/<repo>/<id>/ with mbox, statement, signature, head,
811note status, title, description, meta and diff. Written into a staging folder beside it and renamed
812note into place, so an id folder is always whole and is never written again; the repository's index
813note file gets one line "<id>\n" per patch, appended.
814fn pamkst to bool
815papb
816papt tpsdir
817if not pamkdir
818ret false
819end
820papt tfowner
821if not pamkdir
822ret false
823end
824papc 47
825paprn
826if not pamkdir
827ret false
828end
829papnew part tpdot 0 0
830r = makedir gpp 0 get gppl 0 448
831ret ge r 0
832end
833note pameta: the meta file's six lines: author DID, creation time (s), commits, files, mbox bytes,
834note mbox SHA-256 (the statement's fourth line)
835fn pameta to bool
836palb
837d = get gscur 0
838o = get gsso d
839for i ulong get gssl d bound 128
840palc get gsstr add o i
841end
842palc 10
843paln get gsnow 0
844palc 10
845paln get gpncm 0
846palc 10
847paln get gpnfl 0
848palc 10
849paln get gpmbl 0
850palc 10
851n = get gpstl 0
852for i ulong 64
853palc get gpst add sub n 130 i
854end
855palc 10
856papnew tpfme
857ret pawf 5 get gplnl 0
858end
859note pahdln: gpln = the head commit and a line feed
860fn pahdln to void
861palb
862for i ulong 40
863palc get gphead i
864end
865palc 10
866end
867note pawall9: the nine files into the staging folder; the diff is fxo[0, fxol) (paapply3 left it)
868fn pawall9 to bool
869papnew tpfdf
870if not pawf 6 get fxol 0
871ret false
872end
873papnew tpfmb
874if not pawf 0 get gpmbl 0
875ret false
876end
877papnew tpfst
878if not pawf 1 get gpstl 0
879ret false
880end
881papnew tpfsg
882if not pawf 2 get gpsigl 0
883ret false
884end
885papnew tpftt
886if not pawf 3 get gpttll 0
887ret false
888end
889papnew tpfds
890if not pawf 4 get gpdscl 0
891ret false
892end
893if not pameta
894ret false
895end
896pahdln
897papnew tpfhd
898if not pawf 5 get gplnl 0
899ret false
900end
901papnew tpfss
902ret pawtxt tpopen
903end
904note padrop: remove the staging folder and the files it may hold
905fn padrop1 t view uchar * to void
906papnew t
907x = unlink gpp 0 get gppl 0
908end
909fn padrop to void
910padrop1 tpfdf
911padrop1 tpfmb
912padrop1 tpfst
913padrop1 tpfsg
914padrop1 tpftt
915padrop1 tpfds
916padrop1 tpfme
917padrop1 tpfhd
918padrop1 tpfss
919papnew part tpdot 0 0
920x = rmdir gpp 0 get gppl 0
921end
922note paidxhas: the index (read into fxo) lists gpid
923fn paidxhas to bool
924paprepo
925papt tpindex
926fpb
927for i ulong get gppl 0 bound 4096
928fpc get gpp i
929end
930n = frdall
931if lt n 17
932ret false
933end
934for r ulong div ulong n 17 bound 1048576
935if paidxeq mul r 17
936ret true
937end
938end
939ret false
940end
941fn paidxeq o ulong to bool
942for i ulong 16
943if ne get fxo add o i get gpid i
944ret false
945end
946end
947ret true
948end
949note paidxadd: append "<id>\n" to the index (created 0600), written through
950fn paidxadd to bool
951paprepo
952papt tpindex
953fd = fopen gpp 0 get gppl 0 558145 384
954if lt fd 0
955ret false
956end
957b = new uchar 4096 0
958for i ulong 16
959put b i get gpid i
960end
961put b 16 10
962ok = pawall int fd b 17
963s = fsync int fd
964x = fclose int fd
965ret and ok ge s 0
966end
967note pakeep: staging folder -> <id>/ (rename), then the index line. false when nothing was kept.
968fn pakeep to bool
969if not pamkst
970ret false
971end
972if not pawall9
973padrop
974ret false
975end
976soavb
977papnew part tpdot 0 0
978paavp
979papid part tpdot 0 0
980paavp
981r = renames gspk 0 get gspkl 0 1
982if lt r 0
983padrop
984ret false
985end
986ret paidxadd
987end
988note paavp: one record of the packed list gspk (social/20crypt.om) holding gpp without a final /
989fn paavp to void
990soavopen
991n = get gppl 0
992if gt n 0
993if eq get gpp sub n 1 47
994n = sub n 1
995end
996end
997for i ulong n bound 4096
998soavc get gpp i
999end
1000end
1001note paok st w: the text answer of a kept (201, "accepted") or already known (200, "exists") patch:
1002note its id and the path of its page
1003fn paok st ulong w view uchar * to long
1004patext
1005fput w
1006fput tpaid
1007for i ulong 16
1008fputc get gpid i
1009end
1010fputc 10
1011fput tpapth
1012fputrl
1013fput tppats
1014fputc 47
1015for i ulong 16
1016fputc get gpid i
1017end
1018fputc 10
1019ret long st
1020end
1021note paapply: work folder, the git runs, the store; the work folder is removed whatever happened
1022text tpfsbin "/usr/bin/stat"
1023text tpfstype "-f"
1024text tpfsfmt "--format=%a %S"
1025text tpnosp "patch storage is temporarily unavailable"
1026const PAPRES ulong 1073741824
1027note Keep a reserve for the rest of the forge. Compare blocks without multiplying arbitrary values.
1028fn pafree to bool
1029fkb
1030fka tpfsbin
1031fka tpfstype
1032fka tpfsfmt
1033fka tfdata
1034r = fexec 1000000000
1035if or ne r 0 ne get fxotr 0 0
1036ret false
1037end
1038n = get fxol 0
1039a = ulong 0
1040size = ulong 0
1041p = ulong 0
1042for i ulong n bound 48
1043c = get fxo i
1044if eq c 32
1045p = add i 1
1046break
1047end
1048if or ge i 18 not fisdig c
1049ret false
1050end
1051a = add mul a 10 ulong sub c 48
1052end
1053if or le p 1 ge p n
1054ret false
1055end
1056for i ulong sub n p bound 48
1057c = get fxo add p i
1058if eq c 10
1059break
1060end
1061if or ge i 18 not fisdig c
1062ret false
1063end
1064size = add mul size 10 ulong sub c 48
1065end
1066if eq size 0
1067ret false
1068end
1069ret gt a div PAPRES size
1070end
1071fn paapply to long
1072if not pafree
1073ret parefu 503 tpnosp
1074end
1075if not pastem
1076ret parefu 500 tpmint
1077end
1078r = long 0
1079if pawork
1080r = pamail
1081if eq r 0
1082r = paapply2
1083end
1084else
1085r = parefu 500 tpmint
1086end
1087kept = false
1088if eq r 0
1089kept = pakeep
1090end
1091if not parmtree
1092flog tplrm
1093end
1094if ne r 0
1095ret r
1096end
1097if not kept
1098ret parefu 503 tpmwr
1099end
1100ret paok 201 tpacc
1101end
1102note pasizes: title, description, mbox and sig, each to its own global; 0 or the refusal
1103fn pasizes to long
1104if not patitle
1105ret parefu 400 tpmttl
1106end
1107if not padescr
1108ret parefu 400 tpmdsc
1109end
1110r = pambdec
1111if eq r 413
1112ret parefu 413 tpmbig
1113end
1114if ne r 0
1115ret parefu 400 tpmb64
1116end
1117if not pascan
1118ret parefu 400 tpmnfp
1119end
1120if gt get gpncm 0 100
1121ret parefu 413 tpmmany
1122end
1123if not pasigin
1124ret parefu 400 tpmsigf
1125end
1126ret 0
1127end
1128note patake: POST /<owner>/<repo>/patches/new
1129fn patake to long
1130r = pagate
1131if ne r 0
1132ret r
1133end
1134if not pafall
1135ret parefu 400 tpmform
1136end
1137if not parepok
1138ret parefu 400 tpmrepo
1139end
1140papgs
1141if not paexist
1142ret parefu 404 tpmnogs
1143end
1144if not pabasef
1145ret parefu 400 tpmbase
1146end
1147r = pabasec
1148if ne r 0
1149ret r
1150end
1151r = pasizes
1152if ne r 0
1153ret r
1154end
1155pastmt
1156r = pasigck
1157if ne r 0
1158ret r
1159end
1160papid part tpdot 0 0
1161if paexist
1162if not pasteq
1163ret parefu 409 tpm409
1164end
1165if not paidxhas
1166if not paidxadd
1167ret parefu 503 tpmwr
1168end
1169end
1170ret paok 200 tpexi
1171end
1172if eq get gpgrd 0 2
1173ret parefu 422 tpmbin
1174end
1175if eq get gpgrd 0 3
1176ret parefu 422 tpmpath
1177end
1178ret paapply
1179end