void hcache_writefile(HCACHEFILE *file) { FILE *f; HCACHEDATA *c; int header_count = 0; int maxage; if( !file || !file->dirty || !file->cachefilename ) return; file_mkdir(file->cachefilename); if( ! (f = fopen( file->cachefilename, "wb" ) ) ) return; maxage = cache_maxage(); /* print out the version */ fprintf( f, "@%s@\n", CACHE_FILE_VERSION ); for( c = file->hcachelist; c; c = c->next ) { LISTITEM *l; if( maxage == 0 ) c->age = 0; else if( c->age > maxage ) continue; write_string( f, c->boundname ); write_int( f, (int)c->time ); write_int( f, c->age ); #ifdef OPT_BUILTIN_MD5CACHE_EXT write_md5sum( f, c->rulemd5sum ); #endif write_int( f, list_length( c->includes ) ); for( l = list_first(c->includes); l; l = list_next( l ) ) { write_string( f, list_value(l) ); } write_int( f, list_length( c->hdrscan ) ); for( l = list_first(c->hdrscan); l; l = list_next( l ) ) { write_string( f, list_value(l) ); } fputc( '!', f ); fputc( '\n', f ); ++header_count; } if( DEBUG_HEADER ) printf( "hcache written to %s. %d dependencies, %.0f%% hit rate\n", file->cachefilename, header_count, queries ? 100.0 * hits / queries : 0 ); fclose( f ); }
static void checksums_writefile() { CHECKSUMDATA *c; FILE *f; int maxage; if ( !checksumsdirty ) { return; } maxage = cache_maxage(); f = NULL; for( c = checksumdatalist; c; c = c->next ) { if ( c->mtime == 0 || ismd5empty( (unsigned char*)&c->contentmd5sum ) ) { continue; } if ( maxage == 0 ) { c->age = 0; } else if ( c->age > maxage ) { continue; } if ( !f ) { file_mkdir( checksums_filename() ); if ( !( f = fopen( checksums_filename(), "wb" ) ) ) return; /* print out the version */ fprintf( f, "@%s@\n", CHECKSUM_FILE_VERSION ); } write_string( f, c->boundname ); write_int( f, c->age ); write_int( f, (int)c->mtime ); write_md5sum( f, c->contentmd5sum ); fputc( '!', f ); fputc( '\n', f ); } if ( f ) { fclose( f ); } }
void hcache_done() { FILE *f; HCACHEDATA *c; int header_count = 0; char* hcachename; int maxage; if (!hcachehash) return; if (! (hcachename = cache_name())) return; if (! (f = fopen (hcachename, "wb" ))) return; maxage = cache_maxage(); /* print out the version */ write_netstring(f, CACHE_FILE_VERSION); c = hcachelist; for (c = hcachelist; c; c = c->next) { LIST *l; char time_str[30]; char age_str[30]; char includes_count_str[30]; char hdrscan_count_str[30]; if (maxage == 0) c->age = 0; else if (c->age > maxage) continue; sprintf(includes_count_str, "%lu", list_length(c->includes)); sprintf(hdrscan_count_str, "%lu", list_length(c->hdrscan)); sprintf(time_str, "%lu", c->time); sprintf(age_str, "%lu", c->age); write_netstring(f, CACHE_RECORD_HEADER); write_netstring(f, c->boundname); write_netstring(f, time_str); write_netstring(f, age_str); write_netstring(f, includes_count_str); for (l = c->includes; l; l = list_next(l)) { write_netstring(f, l->string); } write_netstring(f, hdrscan_count_str); for (l = c->hdrscan; l; l = list_next(l)) { write_netstring(f, l->string); } fputs("\n", f); header_count++; } write_netstring(f, CACHE_RECORD_END); if (DEBUG_HEADER) { printf("hcache written to %s. %d dependencies, %.0f%% hit rate\n", hcachename, header_count, queries ? 100.0 * hits / queries : 0); } fclose (f); }
void hcache_done() { FILE * f; HCACHEDATA * c; int header_count = 0; const char * hcachename; int maxage; if ( !hcachehash ) return; if ( !( hcachename = cache_name() ) ) goto cleanup; if ( !( f = fopen( hcachename, "wb" ) ) ) goto cleanup; maxage = cache_maxage(); /* Print out the version. */ write_netstring( f, CACHE_FILE_VERSION ); c = hcachelist; for ( c = hcachelist; c; c = c->next ) { LISTITER iter, end; char time_str[ 30 ]; char age_str[ 30 ]; char includes_count_str[ 30 ]; char hdrscan_count_str[ 30 ]; if ( maxage == 0 ) c->age = 0; else if ( c->age > maxage ) continue; sprintf( includes_count_str, "%lu", (long unsigned) list_length( c->includes ) ); sprintf( hdrscan_count_str, "%lu", (long unsigned) list_length( c->hdrscan ) ); sprintf( time_str, "%lu", (long unsigned) c->time ); sprintf( age_str, "%lu", (long unsigned) c->age ); write_netstring( f, CACHE_RECORD_HEADER ); write_netstring( f, object_str( c->boundname ) ); write_netstring( f, time_str ); write_netstring( f, age_str ); write_netstring( f, includes_count_str ); for ( iter = list_begin( c->includes ), end = list_end( c->includes ); iter != end; iter = list_next( iter ) ) write_netstring( f, object_str( list_item( iter ) ) ); write_netstring( f, hdrscan_count_str ); for ( iter = list_begin( c->hdrscan ), end = list_end( c->hdrscan ); iter != end; iter = list_next( iter ) ) write_netstring( f, object_str( list_item( iter ) ) ); fputs( "\n", f ); ++header_count; } write_netstring( f, CACHE_RECORD_END ); if ( DEBUG_HEADER ) printf( "hcache written to %s. %d dependencies, %.0f%% hit rate\n", hcachename, header_count, queries ? 100.0 * hits / queries : 0 ); fclose ( f ); cleanup: for ( c = hcachelist; c; c = c->next ) { list_free( c->includes ); list_free( c->hdrscan ); object_free( c->boundname ); } hcachelist = 0; if ( hcachehash ) hashdone( hcachehash ); hcachehash = 0; }