about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Middleton <olliemail27@gmail.com>2017-06-09 23:03:08 +0100
committerOliver Middleton <olliemail27@gmail.com>2017-06-09 23:03:08 +0100
commit577c059d5040465bb35afaf605d0f5e49556982f (patch)
treef360c29b03a6cc5873c1892f6a8a7e245567d1e1
parent19193d6390644b5d621934bac6a33caacfb9ad31 (diff)
downloadrust-577c059d5040465bb35afaf605d0f5e49556982f.tar.gz
rust-577c059d5040465bb35afaf605d0f5e49556982f.zip
rustdoc: Use `create_dir_all` to create output directory
Currently rustdoc will fail if passed `-o foo/doc` if the `foo`
directory doesn't exist.

Also remove unneeded `mkdir` as `create_dir_all` can now handle
concurrent invocations.
-rw-r--r--src/librustdoc/html/render.rs25
-rw-r--r--src/test/run-make/rustdoc-output-path/Makefile4
-rw-r--r--src/test/run-make/rustdoc-output-path/foo.rs11
3 files changed, 20 insertions, 20 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index fea059e2757..2b8a18eeb68 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -492,7 +492,7 @@ pub fn run(mut krate: clean::Crate,
             }
         }
     }
-    try_err!(mkdir(&dst), &dst);
+    try_err!(fs::create_dir_all(&dst), &dst);
     krate = render_sources(&dst, &mut scx, krate)?;
     let cx = Context {
         current: Vec::new(),
@@ -658,7 +658,7 @@ fn write_shared(cx: &Context,
     // Write out the shared files. Note that these are shared among all rustdoc
     // docs placed in the output directory, so this needs to be a synchronized
     // operation with respect to all other rustdocs running around.
-    try_err!(mkdir(&cx.dst), &cx.dst);
+    try_err!(fs::create_dir_all(&cx.dst), &cx.dst);
     let _lock = flock::Lock::panicking_new(&cx.dst.join(".lock"), true, true, true);
 
     // Add all the static files. These may already exist, but we just
@@ -808,10 +808,8 @@ fn write_shared(cx: &Context,
 fn render_sources(dst: &Path, scx: &mut SharedContext,
                   krate: clean::Crate) -> Result<clean::Crate, Error> {
     info!("emitting source files");
-    let dst = dst.join("src");
-    try_err!(mkdir(&dst), &dst);
-    let dst = dst.join(&krate.name);
-    try_err!(mkdir(&dst), &dst);
+    let dst = dst.join("src").join(&krate.name);
+    try_err!(fs::create_dir_all(&dst), &dst);
     let mut folder = SourceCollector {
         dst: dst,
         scx: scx,
@@ -825,19 +823,6 @@ 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.
-///
-/// Note that this also handles races as rustdoc is likely to be run
-/// concurrently against another invocation.
-fn mkdir(path: &Path) -> io::Result<()> {
-    match fs::create_dir(path) {
-        Ok(()) => Ok(()),
-        Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()),
-        Err(e) => Err(e)
-    }
-}
-
 /// Takes a path to a source file and cleans the path to it. This canonicalizes
 /// things like ".." to components which preserve the "top down" hierarchy of a
 /// static HTML tree. Each component in the cleaned path will be passed as an
@@ -951,7 +936,7 @@ impl<'a> SourceCollector<'a> {
         let mut href = String::new();
         clean_srcpath(&self.scx.src_root, &p, false, |component| {
             cur.push(component);
-            mkdir(&cur).unwrap();
+            fs::create_dir_all(&cur).unwrap();
             root_path.push_str("../");
             href.push_str(component);
             href.push('/');
diff --git a/src/test/run-make/rustdoc-output-path/Makefile b/src/test/run-make/rustdoc-output-path/Makefile
new file mode 100644
index 00000000000..4e570718a62
--- /dev/null
+++ b/src/test/run-make/rustdoc-output-path/Makefile
@@ -0,0 +1,4 @@
+-include ../tools.mk
+
+all:
+	$(HOST_RPATH_ENV) '$(RUSTDOC)' -o "$(TMPDIR)/foo/bar/doc" foo.rs
diff --git a/src/test/run-make/rustdoc-output-path/foo.rs b/src/test/run-make/rustdoc-output-path/foo.rs
new file mode 100644
index 00000000000..11fc2cd2b8d
--- /dev/null
+++ b/src/test/run-make/rustdoc-output-path/foo.rs
@@ -0,0 +1,11 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub struct Foo;