Add a footer in FileEncoder and check for it in MemDecoder
This commit is contained in:
parent
39e02f1bd1
commit
95150d7246
16 changed files with 115 additions and 52 deletions
|
@ -306,3 +306,9 @@ pub struct DeleteWorkProduct<'a> {
|
|||
pub path: &'a Path,
|
||||
pub err: std::io::Error,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(incremental_corrupt_file)]
|
||||
pub struct CorruptFile<'a> {
|
||||
pub path: &'a Path,
|
||||
}
|
||||
|
|
|
@ -115,7 +115,12 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
|
|||
|
||||
if let LoadResult::Ok { data: (work_products_data, start_pos) } = load_result {
|
||||
// Decode the list of work_products
|
||||
let mut work_product_decoder = MemDecoder::new(&work_products_data[..], start_pos);
|
||||
let Some(mut work_product_decoder) =
|
||||
MemDecoder::new(&work_products_data[..], start_pos)
|
||||
else {
|
||||
sess.dcx().emit_warn(errors::CorruptFile { path: &work_products_path });
|
||||
return LoadResult::DataOutOfDate;
|
||||
};
|
||||
let work_products: Vec<SerializedWorkProduct> =
|
||||
Decodable::decode(&mut work_product_decoder);
|
||||
|
||||
|
@ -145,7 +150,10 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
|
|||
LoadResult::DataOutOfDate => LoadResult::DataOutOfDate,
|
||||
LoadResult::LoadDepGraph(path, err) => LoadResult::LoadDepGraph(path, err),
|
||||
LoadResult::Ok { data: (bytes, start_pos) } => {
|
||||
let mut decoder = MemDecoder::new(&bytes, start_pos);
|
||||
let Some(mut decoder) = MemDecoder::new(&bytes, start_pos) else {
|
||||
sess.dcx().emit_warn(errors::CorruptFile { path: &path });
|
||||
return LoadResult::DataOutOfDate;
|
||||
};
|
||||
let prev_commandline_args_hash = u64::decode(&mut decoder);
|
||||
|
||||
if prev_commandline_args_hash != expected_hash {
|
||||
|
@ -181,9 +189,14 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
|
|||
|
||||
let _prof_timer = sess.prof.generic_activity("incr_comp_load_query_result_cache");
|
||||
|
||||
match load_data(&query_cache_path(sess), sess) {
|
||||
let path = query_cache_path(sess);
|
||||
match load_data(&path, sess) {
|
||||
LoadResult::Ok { data: (bytes, start_pos) } => {
|
||||
Some(OnDiskCache::new(sess, bytes, start_pos))
|
||||
let cache = OnDiskCache::new(sess, bytes, start_pos).unwrap_or_else(|| {
|
||||
sess.dcx().emit_warn(errors::CorruptFile { path: &path });
|
||||
OnDiskCache::new_empty(sess.source_map())
|
||||
});
|
||||
Some(cache)
|
||||
}
|
||||
_ => Some(OnDiskCache::new_empty(sess.source_map())),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue