]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Handle concurrent mkdir requests
authorAlex Crichton <alex@alexcrichton.com>
Mon, 25 Apr 2016 04:37:22 +0000 (21:37 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 25 Apr 2016 04:37:22 +0000 (21:37 -0700)
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`.

src/librustdoc/html/render.rs

index 824265bc3b303432c64b6c665464094d9d3d59dc..c379079054fc6a839ae30e6a707bc8e0b060cad9 100644 (file)
@@ -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)
     }
 }