Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Fix crash when a manifest was evicted but the object is in the cache #237

Merged
merged 2 commits into from
Oct 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ def postprocessUnusableManifestMiss(
section = cache.compilerArtifactsRepository.section(cachekey)
with section.lock, cache.statistics.lock, cache.statistics as stats:
reason(stats)
if returnCode == 0 and os.path.exists(objectFile):
if returnCode == 0 and os.path.exists(objectFile) and not section.hasEntry(cachekey):
artifacts = CompilerArtifacts(objectFile, compilerOutput, compilerStderr)
cleanupRequired = addObjectToCache(stats, cache, section, cachekey, artifacts)
manifest = createOrUpdateManifest(manifestSection, manifestHash, entry)
Expand Down
30 changes: 30 additions & 0 deletions integrationtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,36 @@ def testBasedir(self):
self.assertEqual(stats.numCacheHits(), 1)


class TestCleanCache(unittest.TestCase):
def testEvictedObject(self):
with cd(os.path.join(ASSETS_DIR, "hits-and-misses")), tempfile.TemporaryDirectory() as tempDir:
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
cmd = CLCACHE_CMD + ["/nologo", "/EHsc", "/c", 'hit.cpp']

# Compile once to insert the object in the cache
subprocess.check_call(cmd, env=customEnv)

# Remove object
cache = clcache.Cache(tempDir)
cache.compilerArtifactsRepository.clean(0)

self.assertEqual(subprocess.call(cmd, env=customEnv), 0)

def testEvictedManifest(self):
with cd(os.path.join(ASSETS_DIR, "hits-and-misses")), tempfile.TemporaryDirectory() as tempDir:
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
cmd = CLCACHE_CMD + ["/nologo", "/EHsc", "/c", 'hit.cpp']

# Compile once to insert the object in the cache
subprocess.check_call(cmd, env=customEnv)

# Remove manifest
cache = clcache.Cache(tempDir)
cache.manifestRepository.clean(0)

self.assertEqual(subprocess.call(cmd, env=customEnv), 0)


if __name__ == '__main__':
unittest.TestCase.longMessage = True
unittest.main()