Index: load_cache/load_cache.c =================================================================== --- load_cache/load_cache.c (revision 792) +++ load_cache/load_cache.c (revision 793) @@ -96,37 +96,53 @@ static void ldch_free_file(ldch_ctx_t *ctx, ldch_file_t *file) { ldch_free_file_low(ctx, file); - free(file->name); + free(file->load_name); + free(file->real_name); free(file); } +static char *get_real_name(ldch_ctx_t *ctx, const char *load_name) +{ + if (ctx->load_name_to_real_name != NULL) + return ctx->load_name_to_real_name(ctx, load_name); + return ldch_strdup(load_name); +} -ldch_data_t *ldch_load_(ldch_ctx_t *ctx, const char *filename, ldch_low_parser_t *low, ldch_high_parser_t *high, void *low_call_ctx, void *high_call_ctx) +ldch_data_t *ldch_load_(ldch_ctx_t *ctx, const char *load_name, ldch_low_parser_t *low, ldch_high_parser_t *high, void *low_call_ctx, void *high_call_ctx) { - ldch_file_t *file = htsp_get(&ctx->files, filename); + ldch_file_t *file = htsp_get(&ctx->files, load_name); void **d; ldch_data_t *data; - double fmd = ldch_file_mtime(filename); - if (fmd < 0) - return NULL; - /* get low level */ if (file == NULL) { - file = low->parse_alloc(low, low_call_ctx, filename); - if (file == NULL) + char *real_name = get_real_name(ctx, load_name); + if (real_name == NULL) return NULL; - if (low->parse(low, low_call_ctx, file, filename) != 0) + file = low->parse_alloc(low, low_call_ctx, real_name); + if (file == NULL) { + free(real_name); + return NULL; + } + file->real_name = real_name; + file->load_name = ldch_strdup(load_name); + if (low->parse(low, low_call_ctx, file, file->real_name) != 0) { ldch_unload(ctx, file); - file->last_low_parsed = fmd; + return NULL; + } + file->last_low_parsed = ldch_file_mtime(file->real_name); + htsp_set(&ctx->files, file->load_name, file); } else { + double fmd = ldch_file_mtime(file->real_name); + if (fmd < 0) + return NULL; if (low->uid != file->low_parser->uid) return NULL; /* can't parse the same file twice, with different low level */ if (fmd > file->last_low_parsed) { /* changed on disk */ ldch_free_file_low(ctx, file); - low->parse(low, low_call_ctx, file, filename); + low->parse(low, low_call_ctx, file, file->real_name); } } @@ -136,7 +152,7 @@ return NULL; /* allocation error */ if (*d == NULL) { - data = high->parse(high, high_call_ctx, file, filename); + data = high->parse(high, high_call_ctx, file); if (data == NULL) return NULL; *d = data; @@ -149,7 +165,7 @@ } -ldch_data_t *ldch_load(ldch_ctx_t *ctx, const char *filename, const char *lows, const char *highs, void *low_call_ctx, void *high_call_ctx) +ldch_data_t *ldch_load(ldch_ctx_t *ctx, const char *load_name, const char *lows, const char *highs, void *low_call_ctx, void *high_call_ctx) { ldch_low_parser_t *low; ldch_high_parser_t *high; @@ -162,12 +178,12 @@ if (high == NULL) return NULL; - return ldch_load_(ctx, filename, low, high, low_call_ctx, high_call_ctx); + return ldch_load_(ctx, load_name, low, high, low_call_ctx, high_call_ctx); } void ldch_unload(ldch_ctx_t *ctx, ldch_file_t *file) { - htsp_pop(&ctx->files, file->name); + htsp_pop(&ctx->files, file->load_name); ldch_free_file(ctx, file); } Index: load_cache/load_cache.h =================================================================== --- load_cache/load_cache.h (revision 792) +++ load_cache/load_cache.h (revision 793) @@ -20,7 +20,7 @@ struct ldch_high_parser_s { char *name; - ldch_data_t *(*parse)(ldch_high_parser_t *parser, void *call_ctx, ldch_file_t *file, const char *fn); + ldch_data_t *(*parse)(ldch_high_parser_t *parser, void *call_ctx, ldch_file_t *file); void (*free_payload)(ldch_data_t *data); void (*unreg)(ldch_ctx_t *ctx, ldch_high_parser_t *high); void *used_data; @@ -35,7 +35,8 @@ struct ldch_file_s { ldch_ctx_t *parent; - char *name; /* file name */ + char *load_name; /* file name: as the user refers to it (strdup'd variant, also the hash key) */ + char *real_name; /* file name: full path on the file system */ vtp0_t data; /* -> (ldch_data_t *), indexed by high_parser uid */ void *user_data; ldch_low_parser_t *low_parser; @@ -48,6 +49,7 @@ htsp_t low_parsers; htsp_t high_parsers; htsp_t files; /* of ldch_file_t */ + char *(*load_name_to_real_name)(ldch_ctx_t *ctx, const char *load_name); /* simple strdup() if NULL */ void *user_data; ldch_uid_t next_low_uid; }; @@ -64,8 +66,8 @@ /* Load a file from disk or from memory; in any case if the modification timestamp on disk is higher than the cached timestamp, reload the file */ -ldch_data_t *ldch_load_(ldch_ctx_t *ctx, const char *filename, ldch_low_parser_t *low, ldch_high_parser_t *high, void *low_call_ctx, void *high_call_ctx); -ldch_data_t *ldch_load(ldch_ctx_t *ctx, const char *filename, const char *low, const char *high, void *low_call_ctx, void *high_call_ctx); +ldch_data_t *ldch_load_(ldch_ctx_t *ctx, const char *load_name, ldch_low_parser_t *low, ldch_high_parser_t *high, void *low_call_ctx, void *high_call_ctx); +ldch_data_t *ldch_load(ldch_ctx_t *ctx, const char *load_name, const char *low, const char *high, void *low_call_ctx, void *high_call_ctx); /* Remove a single file from a context, freeing all memory taken by the parsed data. Will be re-loaded upon next request */