Rework inbox

master
teknomunk 1 year ago
parent 9d43a84d5b
commit a4e7e5a29e

@ -57,8 +57,19 @@ bool route_inbox( struct http_request* req )
clock_gettime( CLOCK_REALTIME, &ts );
time_ns = (uint64_t)ts.tv_sec * 1000000000 + (uint64_t)ts.tv_nsec;
int head = 0;
FILE* head_f = fopen("data/inbox/HEAD","r");
fscanf( head_f, "%d", &head );
fclose( head_f );
head += 1;
head_f = fopen("data/inbox/HEAD.tmp","w");
fprintf( head_f, "%d", head );
fclose( head_f );
rename( "data/inbox/HEAD.tmp", "data/inbox/HEAD" );
char filename[512];
snprintf( filename, 512, "data/inbox/%llu.json", time_ns );
snprintf( filename, 512, "data/inbox/%d.json", head );
char tmp_filename[512+32];
snprintf( tmp_filename, 512+32, "%s.tmp-%d", filename, rand() );

@ -1,5 +1,5 @@
{
"signature": "%( write_json_escaped( f, signature ); )",
"date": "%( write_json_escaped( f, signature ); )",
"when": "%llu{time_ns}",
"body": %( io_copy( body, f ); )
}

Loading…
Cancel
Save