code wiki / (root) / nx_torrent_acquisition_cli_gate_t270.nx

nx_torrent_acquisition_cli_gate_t270.nx source

↩ module page · 36 lines · 2377 B

1import "nx_site_publish_lib.nx" 2import "nx_tool_run.nx" 3import "nx_gate_verdict.nx" 4func tq_call(exe:*u8,magnet:*u8,dest:*u8,flag:*u8,timeout:i64)->i64{ 5 let av:*i64=sys_mmap(7*__size_of(i64)) as *i64 6 av[0]=exe as i64;av[1]=magnet as i64;av[2]=dest as i64;av[3]="--acquire-only" as *u8 as i64;av[4]=flag as i64;av[5]=0 7 let out:*u8=sys_mmap(PB_CONFCAP);let n:*i64=sys_mmap(__size_of(i64)) as *i64 8 let rc:i64=tr_run_capture_cwd(exe,av,out,PB_CONFCAP,n,timeout,".") 9 if n[0]>0{sys_write(1,out,n[0])} 10 sys_munmap(av as *u8,7*__size_of(i64));sys_munmap(out,PB_CONFCAP);sys_munmap(n as *u8,__size_of(i64)) 11 return rc 12} 13func main(argc:i64,argv:*i64)->i64{ 14 if argc!=7{return 2} 15 let artifact:*i64=sys_mmap(2*__size_of(i64)) as *i64 16 if rm_artifact(argv[1] as *u8,argv[3] as *u8,argv[2] as *u8,artifact)!=0{return 3} 17 sys_munmap(artifact[0] as *u8,artifact[1]+1) 18 let timeout:i64=pb_sized_bytes(argv[6] as *u8);if timeout<=0{return 2} 19 let c:*i64=gv_ctr() 20 let absent:*u8=argv[4] as *u8;let check:i64=sys_openat_rd(absent) 21 if check>=0{sys_close(check);return 8} 22 gv_check("fresh destination absent before preflight",check==(0-2),c) 23 gv_check("valid acquisition preflight returns",tq_call(argv[1] as *u8,argv[5] as *u8,absent,"--preflight",timeout)==0,c) 24 let after:i64=sys_openat_rd(absent);gv_check("preflight creates no destination",after==(0-2),c);if after>=0{sys_close(after)} 25 gv_check("invalid magnet refused before destination",tq_call(argv[1] as *u8,"invalid",absent,"--preflight",timeout)==2,c) 26 gv_check("unknown operation refused",tq_call(argv[1] as *u8,argv[5] as *u8,absent,"--wrong",timeout)==2,c) 27 if sys_mkdir(absent,0x1c0)!=0{return 4} 28 let path:*u8=sys_mmap(PB_PATH);let pos:*i64=sys_mmap(__size_of(i64)) as *i64;pos[0]=0 29 pb_app(path,pos,absent);pb_app(path,pos,"/download.part") 30 let sentinel:*u8="retained partial game bytes" 31 if fsx_write(path,sentinel,vw_slen(sentinel))!=vw_slen(sentinel){return 4} 32 gv_check("resume preflight returns",tq_call(argv[1] as *u8,argv[5] as *u8,absent,"--preflight",timeout)==0,c) 33 let got:*u8=sys_mmap(vw_slen(sentinel)+1);let size:i64=pb_read_bounded(path,got,vw_slen(sentinel)+1) 34 gv_check("existing partial bytes preserved",pb_same_bytes(got,size,sentinel,vw_slen(sentinel))==1,c) 35 return gv_verdict("TORRENT-ACQUISITION-PREFLIGHT",c,"actual pinned ELF; no transfer; destination and resume validation remain unqualified") 36}