Skip to content

Commit

Permalink
fs: use an iterative algorithm for 'mkdir_recursive'
Browse files Browse the repository at this point in the history
as requested in #6109
  • Loading branch information
lbonn committed Mar 10, 2014
1 parent 62f1d68 commit 0fcd5d5
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/libstd/io/fs.rs
Expand Up @@ -528,10 +528,25 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> {
if path.is_dir() {
return Ok(())
}
if path.filename().is_some() {
try!(mkdir_recursive(&path.dir_path(), mode));

let mut comps = path.components();
let mut curpath = path.root_path().unwrap_or(Path::new("."));

for c in comps {
curpath.push(c);

match mkdir(&curpath, mode) {
Err(mkdir_err) => {
// already exists ?
if try!(stat(&curpath)).kind != io::TypeDirectory {
return Err(mkdir_err);
}
}
Ok(()) => ()
}
}
mkdir(path, mode)

Ok(())
}

/// Removes a directory at this path, after removing all its contents. Use
Expand Down

0 comments on commit 0fcd5d5

Please sign in to comment.