@@ -125,6 +125,21 @@ pub struct SharedContext {
125
125
/// Warnings for the user if rendering would differ using different markdown
126
126
/// parsers.
127
127
pub markdown_warnings : RefCell < Vec < ( Span , String , Vec < html_diff:: Difference > ) > > ,
128
+ /// The directories that have already been created in this doc run. Used to reduce the number
129
+ /// of spurious `create_dir_all` calls.
130
+ pub created_dirs : RefCell < FxHashSet < PathBuf > > ,
131
+ }
132
+
133
+ impl SharedContext {
134
+ fn ensure_dir ( & self , dst : & Path ) -> io:: Result < ( ) > {
135
+ let mut dirs = self . created_dirs . borrow_mut ( ) ;
136
+ if !dirs. contains ( dst) {
137
+ fs:: create_dir_all ( dst) ?;
138
+ dirs. insert ( dst. to_path_buf ( ) ) ;
139
+ }
140
+
141
+ Ok ( ( ) )
142
+ }
128
143
}
129
144
130
145
/// Indicates where an external crate can be found.
@@ -460,6 +475,7 @@ pub fn run(mut krate: clean::Crate,
460
475
} ,
461
476
css_file_extension : css_file_extension. clone ( ) ,
462
477
markdown_warnings : RefCell :: new ( vec ! [ ] ) ,
478
+ created_dirs : RefCell :: new ( FxHashSet ( ) ) ,
463
479
} ;
464
480
465
481
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -790,7 +806,6 @@ fn write_shared(cx: &Context,
790
806
// Write out the shared files. Note that these are shared among all rustdoc
791
807
// docs placed in the output directory, so this needs to be a synchronized
792
808
// operation with respect to all other rustdocs running around.
793
- try_err ! ( fs:: create_dir_all( & cx. dst) , & cx. dst) ;
794
809
let _lock = flock:: Lock :: panicking_new ( & cx. dst . join ( ".lock" ) , true , true , true ) ;
795
810
796
811
// Add all the static files. These may already exist, but we just
@@ -1503,8 +1518,8 @@ impl Context {
1503
1518
this. render_item ( & mut buf, & item, false ) . unwrap ( ) ;
1504
1519
// buf will be empty if the module is stripped and there is no redirect for it
1505
1520
if !buf. is_empty ( ) {
1521
+ try_err ! ( this. shared. ensure_dir( & this. dst) , & this. dst) ;
1506
1522
let joint_dst = this. dst . join ( "index.html" ) ;
1507
- try_err ! ( fs:: create_dir_all( & this. dst) , & this. dst) ;
1508
1523
let mut dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1509
1524
try_err ! ( dst. write_all( & buf) , & joint_dst) ;
1510
1525
}
@@ -1538,8 +1553,8 @@ impl Context {
1538
1553
let name = item. name . as_ref ( ) . unwrap ( ) ;
1539
1554
let item_type = item. type_ ( ) ;
1540
1555
let file_name = & item_path ( item_type, name) ;
1556
+ try_err ! ( self . shared. ensure_dir( & self . dst) , & self . dst) ;
1541
1557
let joint_dst = self . dst . join ( file_name) ;
1542
- try_err ! ( fs:: create_dir_all( & self . dst) , & self . dst) ;
1543
1558
let mut dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1544
1559
try_err ! ( dst. write_all( & buf) , & joint_dst) ;
1545
1560
0 commit comments