fs: use an iterative algorithm for 'mkdir_recursive'

as requested in #6109
This commit is contained in:
Laurent Bonnans 2014-02-26 17:50:02 +01:00
parent 62f1d68439
commit 0fcd5d5455

View File

@ -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