Skip to content

Commit 577c059

Browse files
committed
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.
1 parent 19193d6 commit 577c059

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/librustdoc/html/render.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ pub fn run(mut krate: clean::Crate,
492492
}
493493
}
494494
}
495-
try_err!(mkdir(&dst), &dst);
495+
try_err!(fs::create_dir_all(&dst), &dst);
496496
krate = render_sources(&dst, &mut scx, krate)?;
497497
let cx = Context {
498498
current: Vec::new(),
@@ -658,7 +658,7 @@ fn write_shared(cx: &Context,
658658
// Write out the shared files. Note that these are shared among all rustdoc
659659
// docs placed in the output directory, so this needs to be a synchronized
660660
// operation with respect to all other rustdocs running around.
661-
try_err!(mkdir(&cx.dst), &cx.dst);
661+
try_err!(fs::create_dir_all(&cx.dst), &cx.dst);
662662
let _lock = flock::Lock::panicking_new(&cx.dst.join(".lock"), true, true, true);
663663

664664
// Add all the static files. These may already exist, but we just
@@ -808,10 +808,8 @@ fn write_shared(cx: &Context,
808808
fn render_sources(dst: &Path, scx: &mut SharedContext,
809809
krate: clean::Crate) -> Result<clean::Crate, Error> {
810810
info!("emitting source files");
811-
let dst = dst.join("src");
812-
try_err!(mkdir(&dst), &dst);
813-
let dst = dst.join(&krate.name);
814-
try_err!(mkdir(&dst), &dst);
811+
let dst = dst.join("src").join(&krate.name);
812+
try_err!(fs::create_dir_all(&dst), &dst);
815813
let mut folder = SourceCollector {
816814
dst: dst,
817815
scx: scx,
@@ -825,19 +823,6 @@ fn write(dst: PathBuf, contents: &[u8]) -> Result<(), Error> {
825823
Ok(try_err!(try_err!(File::create(&dst), &dst).write_all(contents), &dst))
826824
}
827825

828-
/// Makes a directory on the filesystem, failing the thread if an error occurs
829-
/// and skipping if the directory already exists.
830-
///
831-
/// Note that this also handles races as rustdoc is likely to be run
832-
/// concurrently against another invocation.
833-
fn mkdir(path: &Path) -> io::Result<()> {
834-
match fs::create_dir(path) {
835-
Ok(()) => Ok(()),
836-
Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()),
837-
Err(e) => Err(e)
838-
}
839-
}
840-
841826
/// Takes a path to a source file and cleans the path to it. This canonicalizes
842827
/// things like ".." to components which preserve the "top down" hierarchy of a
843828
/// static HTML tree. Each component in the cleaned path will be passed as an
@@ -951,7 +936,7 @@ impl<'a> SourceCollector<'a> {
951936
let mut href = String::new();
952937
clean_srcpath(&self.scx.src_root, &p, false, |component| {
953938
cur.push(component);
954-
mkdir(&cur).unwrap();
939+
fs::create_dir_all(&cur).unwrap();
955940
root_path.push_str("../");
956941
href.push_str(component);
957942
href.push('/');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(HOST_RPATH_ENV) '$(RUSTDOC)' -o "$(TMPDIR)/foo/bar/doc" foo.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub struct Foo;

0 commit comments

Comments
 (0)