Skip to content

Commit 897199a

Browse files
committed
Auto merge of #33191 - alexcrichton:rustdoc-create-dir-all-racy, r=steveklabnik
rustdoc: Handle concurrent mkdir requests It's likely that `rustdoc` as a tool is run concurrently in the same output (e.g. documenting multiple crates as Cargo does), in which case it needs to handle concurrent calls to `fs::create_dir`.
2 parents 01a0207 + 36d9ee3 commit 897199a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/librustdoc/html/render.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,16 @@ fn write(dst: PathBuf, contents: &[u8]) -> Result<(), Error> {
820820
Ok(try_err!(try_err!(File::create(&dst), &dst).write_all(contents), &dst))
821821
}
822822

823-
/// Makes a directory on the filesystem, failing the thread if an error occurs and
824-
/// skipping if the directory already exists.
823+
/// Makes a directory on the filesystem, failing the thread if an error occurs
824+
/// and skipping if the directory already exists.
825+
///
826+
/// Note that this also handles races as rustdoc is likely to be run
827+
/// concurrently against another invocation.
825828
fn mkdir(path: &Path) -> io::Result<()> {
826-
if !path.exists() {
827-
fs::create_dir(path)
828-
} else {
829-
Ok(())
829+
match fs::create_dir(path) {
830+
Ok(()) => Ok(()),
831+
Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()),
832+
Err(e) => Err(e)
830833
}
831834
}
832835

0 commit comments

Comments
 (0)