Skip to content

Commit e25dfe1

Browse files
authored
Rollup merge of #114976 - Enselic:incr-comp-dir-error, r=compiler-errors
Ignore unexpected incr-comp session dirs Clearly the code path can be hit without the presence of a compiler bug. All it takes is mischief. See #71698. Ignore problematic directories instead of ICE:ing. `continue`ing is already done for problematic dirs in the code block above us. Closes #71698. With this fix, the output is this instead of ICE: ``` $ cargo +stage1 new gz-ice && cd gz-ice $ cargo +stage1 build $ find target -type f -exec gzip {} \; $ cargo +stage1 run Created binary (application) `gz-ice` package Compiling gz-ice v0.1.0 (/tmp/gz-ice) Finished dev [unoptimized + debuginfo] target(s) in 0.13s gzip: target/debug/gz-ice has 1 other link -- unchanged gzip: target/debug/deps/gz_ice-de919414dd9926b9 has 1 other link -- unchanged Compiling gz-ice v0.1.0 (/tmp/gz-ice) warning: failed to garbage collect invalid incremental compilation session directory `/tmp/gz-ice/target/debug/incremental/gz_ice-23qx9z9j9vghe/s-gnwd8daity-kp10sj.lock.gz`: Not a directory (os error 20) warning: `gz-ice` (bin "gz-ice") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.13s Running `target/debug/gz-ice` Hello, world! ```
2 parents 7b66abe + 64e8aea commit e25dfe1

File tree

1 file changed

+12
-8
lines changed
  • compiler/rustc_incremental/src/persist

1 file changed

+12
-8
lines changed

compiler/rustc_incremental/src/persist/fs.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,13 @@ where
538538
continue;
539539
}
540540

541-
let timestamp = extract_timestamp_from_session_dir(&directory_name).unwrap_or_else(|_| {
542-
bug!("unexpected incr-comp session dir: {}", session_dir.display())
543-
});
541+
let timestamp = match extract_timestamp_from_session_dir(&directory_name) {
542+
Ok(timestamp) => timestamp,
543+
Err(e) => {
544+
debug!("unexpected incr-comp session dir: {}: {}", session_dir.display(), e);
545+
continue;
546+
}
547+
};
544548

545549
if timestamp > best_candidate.0 {
546550
best_candidate = (timestamp, Some(session_dir.clone()));
@@ -562,14 +566,14 @@ fn is_session_directory_lock_file(file_name: &str) -> bool {
562566
file_name.starts_with("s-") && file_name.ends_with(LOCK_FILE_EXT)
563567
}
564568

565-
fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime, ()> {
569+
fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime, &'static str> {
566570
if !is_session_directory(directory_name) {
567-
return Err(());
571+
return Err("not a directory");
568572
}
569573

570574
let dash_indices: Vec<_> = directory_name.match_indices('-').map(|(idx, _)| idx).collect();
571575
if dash_indices.len() != 3 {
572-
return Err(());
576+
return Err("not three dashes in name");
573577
}
574578

575579
string_to_timestamp(&directory_name[dash_indices[0] + 1..dash_indices[1]])
@@ -581,11 +585,11 @@ fn timestamp_to_string(timestamp: SystemTime) -> String {
581585
base_n::encode(micros as u128, INT_ENCODE_BASE)
582586
}
583587

584-
fn string_to_timestamp(s: &str) -> Result<SystemTime, ()> {
588+
fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
585589
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);
586590

587591
if micros_since_unix_epoch.is_err() {
588-
return Err(());
592+
return Err("timestamp not an int");
589593
}
590594

591595
let micros_since_unix_epoch = micros_since_unix_epoch.unwrap();

0 commit comments

Comments
 (0)