jam: get_jcache(): clean up when reading the cache failed
When reading the cache file failed we have to assume it is corrupt and
we should use any entries read from it. So now we remove the ones we
read again.
Diff
jam/jcache.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
@@ -637,8 +637,49 @@
jamfileCache = new_jamfile_cache();
if (jamfileCache && !jamfileCache->cache_file) {
char* filename = jcache_name();
if (filename)
read_jcache(jamfileCache, filename);
if (filename) {
if (!read_jcache(jamfileCache, filename)) {
int count = jamfileCache->filenames->count;
int i;
jamfile_cache* newCache = new_jamfile_cache();
if (!newCache) {
fprintf(stderr, "Out of memory!\n");
exit(1);
}
for (i = 0; i < count; i++) {
char* entryname = jamfileCache->filenames->strings[i];
jcache_entry* entry = find_jcache_entry(jamfileCache,
entryname);
if (entry->used) {
jcache_entry newEntry;
if (!init_jcache_entry(&newEntry, entryname,
entry->time, entry->used)) {
fprintf(stderr, "Out of memory!\n");
exit(1);
}
delete_string_list(newEntry.strings);
newEntry.strings = entry->strings;
entry->strings = 0;
if (!add_jcache_entry(newCache, &newEntry)) {
fprintf(stderr, "Out of memory!\n");
exit(1);
}
}
}
delete_jamfile_cache(jamfileCache);
jamfileCache = newCache;
jamfileCache->cache_file = filename;
}
}
}
return jamfileCache;
}