Skip to content

Commit cb21e64

Browse files
committed
Improve & fix doc dir removal process
1 parent 7c45021 commit cb21e64

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,19 @@ impl RustDocFingerprint {
773773
)
774774
}
775775

776+
fn remove_doc_dirs(doc_dirs: &Vec<PathBuf>) -> CargoResult<()> {
777+
let errs: Vec<CargoResult<()>> = doc_dirs
778+
.iter()
779+
.map(|path| paths::remove_dir_all(&path))
780+
.filter(|res| res.is_err())
781+
.collect();
782+
if !errs.is_empty() {
783+
Err(anyhow::anyhow!("Dir removal error"))
784+
} else {
785+
Ok(())
786+
}
787+
}
788+
776789
/// This function checks whether the latest version of `Rustc` used to compile this
777790
/// `Workspace`'s docs was the same as the one is currently being used in this `cargo doc`
778791
/// call.
@@ -804,9 +817,7 @@ impl RustDocFingerprint {
804817
// Check if rustc_version matches the one we just used. Otherways,
805818
// remove the `doc` folder to trigger a re-compilation of the docs.
806819
if fingerprint.rustc_vv != actual_rustdoc_target_data.rustc_vv {
807-
doc_dirs
808-
.iter()
809-
.try_for_each(|path| paths::remove_dir_all(&path))?;
820+
Self::remove_doc_dirs(&doc_dirs)?;
810821
actual_rustdoc_target_data.write(cx)?
811822
}
812823
}
@@ -816,9 +827,7 @@ impl RustDocFingerprint {
816827
// exists neither, we simply do nothing and continue.
817828
Err(_) => {
818829
// We don't care if this suceeds as explained above.
819-
let _ = doc_dirs
820-
.iter()
821-
.try_for_each(|path| paths::remove_dir_all(&path));
830+
let _ = Self::remove_doc_dirs(&doc_dirs);
822831
actual_rustdoc_target_data.write(cx)?
823832
}
824833
}

tests/testsuite/doc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,7 @@ LLVM version: 9.0
17231723
);
17241724
}
17251725

1726+
#[cfg(target_os = "linux")]
17261727
#[cargo_test]
17271728
fn doc_fingerprint_respects_target_paths() {
17281729
// Random rustc verbose version

0 commit comments

Comments
 (0)