From 01b43dff725a475b276bdbcf5ab2e768c51dea0d Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Mon, 12 Nov 2018 08:33:07 +0000 Subject: [PATCH] JavaScript: Make in-dist trap cache read-only. --- .../src/com/semmle/js/extractor/AutoBuild.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java index b38e2898900..efb77fe25d1 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java +++ b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java @@ -380,8 +380,16 @@ public class AutoBuild { ITrapCache trapCache = this.trapCache; if (trapCache instanceof DummyTrapCache) { Path trapCachePath = SEMMLE_DIST.resolve(".cache").resolve("trap-cache").resolve("javascript"); - if (Files.isDirectory(trapCachePath)) - trapCache = new DefaultTrapCache(trapCachePath.toString(), null, Main.EXTRACTOR_VERSION); + if (Files.isDirectory(trapCachePath)) { + trapCache = new DefaultTrapCache(trapCachePath.toString(), null, Main.EXTRACTOR_VERSION) { + @Override + public File lookup(String source, ExtractorConfig config, FileType type) { + File f = super.lookup(source, config, type); + // only return `f` if it exists; this has the effect of making the cache read-only + return f.exists() ? f : null; + } + }; + } } FileExtractor extractor = new FileExtractor(config, outputConfig, trapCache, extractorState);