about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-04-24 21:37:22 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-04-24 21:37:22 -0700
commit36d9ee3da983a318f958077dbc68ba1adfae98b8 (patch)
tree1bc614126f70c44eca3cd4b1802e58c0a6eea3c8
parent8d0dd7876e733555b0284e9b6cbf0f33ed792b67 (diff)
downloadrust-36d9ee3da983a318f958077dbc68ba1adfae98b8.tar.gz
rust-36d9ee3da983a318f958077dbc68ba1adfae98b8.zip
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`.
-rw-r--r--src/librustdoc/html/render.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 824265bc3b3..c379079054f 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -820,13 +820,16 @@ fn write(dst: PathBuf, contents: &[u8]) -> Result<(), Error> {
     Ok(try_err!(try_err!(File::create(&dst), &dst).write_all(contents), &dst))
 }
 
-/// Makes a directory on the filesystem, failing the thread if an error occurs and
-/// skipping if the directory already exists.
+/// Makes a directory on the filesystem, failing the thread if an error occurs
+/// and skipping if the directory already exists.
+///
+/// Note that this also handles races as rustdoc is likely to be run
+/// concurrently against another invocation.
 fn mkdir(path: &Path) -> io::Result<()> {
-    if !path.exists() {
-        fs::create_dir(path)
-    } else {
-        Ok(())
+    match fs::create_dir(path) {
+        Ok(()) => Ok(()),
+        Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()),
+        Err(e) => Err(e)
     }
 }