char/sorcery
static-files based git repo viewer
git clone https://git.t4t.associates/char/sorcery
3356bff
main
1const std =@import ( "std" ); 2 3/// Ask sorceryd to rebuild the site for `repo_path` now rather than on its 4/// next scan, and relay the site URL it reports so the pusher can find it. 5pub fn request ( io : std . Io , environ : * const std . process . Environ . Map , repo_path : [] const u8 ) void { 6const socket =environ . get ( "SORCERY_CONTROL_SOCKET" ) orelse return ; 7send ( io , socket , repo_path ) catch | err | std . log . warn ( "site refresh failed: {} " , .{ err }); 8} 9 10fn send ( io : std . Io , socket_path : [] const u8 , repo_path : [] const u8 ) ! void { 11const address =try std . Io . net . UnixAddress . init ( socket_path ); 12const stream =try address . connect ( io ); 13defer stream . close ( io ); 14 15var write_buffer : [ 256 ] u8 =undefined ; 16var stream_writer =stream . writer ( io , & write_buffer ); 17try stream_writer . interface . ( " { s } \n" , .{ repo_path }); 18try stream_writer . interface . flush (); 19 20var read_buffer : [ 1024 ] u8 =undefined ; 21var stream_reader =stream . reader ( io , & read_buffer ); 22const reply =try stream_reader . interface . takeDelimiter ( '\n' ) orelse return error . EmptyReply ; 23if ( std . mem . eql ( u8 , reply , "ok" )) return ; 24if ( std . mem . startsWith ( u8 , reply , "ok " )) { 25std . debug . ( "sorcery: { s } \n" , .{ reply [ "ok " . len ..]}); 26} else { 27std . log . warn ( "site refresh failed: { s } " , .{ reply }); 28} 29}