⛏️ index : buildtools.git

author Ingo Weinhold <ingo_weinhold@gmx.de> 2013-07-25 22:55:11.0 +02:00:00
committer Ingo Weinhold <ingo_weinhold@gmx.de> 2013-07-25 22:55:11.0 +02:00:00
commit
502f1ff979aae8f4ce4805ffa8a779819ecf6936 [patch]
tree
fbccb52d3c049d1b4eabd36e1b3d1f3a11a815eb
parent
bbab887c2f0f0370d3423aec9a8504b76c091fe6
download
502f1ff979aae8f4ce4805ffa8a779819ecf6936.tar.gz

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(-)

diff --git a/jam/jcache.c b/jam/jcache.c
index 16dd816..c7b8c75 100644
--- a/jam/jcache.c
+++ b/jam/jcache.c
@@ -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)) {
				// An error occurred while reading the cache file. Remove all
				// entries that we read in, assuming they might be corrupted.
				// Since the hash doesn't support removing entries, we create
				// a new one and copy over the entries we want to keep.
				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;
}