diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-07-30 12:09:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-30 12:09:12 -0400 |
commit | 2703996dea73c496d79fcedf165886a1659622d1 (patch) | |
tree | 9e1972ab89121b68fd973c930e60e6a3b41a76b5 /cli/cache/emit.rs | |
parent | ef5653be9823065e14189e412b52296bc4aeecb9 (diff) |
refactor(emit/cache): move cli version into emit hash (#15348)
Diffstat (limited to 'cli/cache/emit.rs')
-rw-r--r-- | cli/cache/emit.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/cli/cache/emit.rs b/cli/cache/emit.rs index 5260a7fb3..b3edcbc69 100644 --- a/cli/cache/emit.rs +++ b/cli/cache/emit.rs @@ -16,8 +16,6 @@ use super::FastInsecureHasher; struct EmitMetadata { pub source_hash: String, pub emit_hash: String, - // purge the cache between cli versions - pub cli_version: String, } /// The cache that stores previously emitted files. @@ -54,9 +52,6 @@ impl EmitCache { // load and verify the meta data file is for this source and CLI version let bytes = self.disk_cache.get(&meta_filename).ok()?; let meta: EmitMetadata = serde_json::from_slice(&bytes).ok()?; - if meta.cli_version != self.cli_version { - return None; - } if let Some(expected_source_hash) = expected_source_hash { if meta.source_hash != expected_source_hash.to_string() { return None; @@ -65,7 +60,7 @@ impl EmitCache { // load and verify the emit is for the meta data let emit_bytes = self.disk_cache.get(&emit_filename).ok()?; - if meta.emit_hash != compute_emit_hash(&emit_bytes) { + if meta.emit_hash != compute_emit_hash(&emit_bytes, &self.cli_version) { return None; } @@ -119,9 +114,8 @@ impl EmitCache { // save the metadata let metadata = EmitMetadata { - cli_version: self.cli_version.to_string(), source_hash: source_hash.to_string(), - emit_hash: compute_emit_hash(code.as_bytes()), + emit_hash: compute_emit_hash(code.as_bytes(), &self.cli_version), }; self .disk_cache @@ -146,11 +140,16 @@ impl EmitCache { } } -fn compute_emit_hash(bytes: &[u8]) -> String { +fn compute_emit_hash(bytes: &[u8], cli_version: &str) -> String { // it's ok to use an insecure hash here because // if someone can change the emit source then they // can also change the version hash - FastInsecureHasher::new().write(bytes).finish().to_string() + FastInsecureHasher::new() + .write(bytes) + // emit should not be re-used between cli versions + .write(cli_version.as_bytes()) + .finish() + .to_string() } #[cfg(test)] |