diff options
| author | bors <bors@rust-lang.org> | 2013-04-27 17:24:33 -0700 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-04-27 17:24:33 -0700 | 
| commit | dd5b1de1812f308ad68472d2ab06c15d3c342d75 (patch) | |
| tree | 6cca3a72f779c525e697e861b614159b37c486c7 /src/librustpkg/path_util.rs | |
| parent | 88dd53a75441d25a060fb7dc7131ea3772383562 (diff) | |
| parent | 848641fcb54c282f6bd616ef1d6ac06087d778f6 (diff) | |
| download | rust-dd5b1de1812f308ad68472d2ab06c15d3c342d75.tar.gz rust-dd5b1de1812f308ad68472d2ab06c15d3c342d75.zip | |
auto merge of #6082 : catamorphism/rust/mkdir_recursive, r=brson
r? @brson mkdir_recursive creates a directory as well as any of its parent directories that don't exist already. Seems like a useful thing to have in core. (Or r? anyone who gets to it first.)
Diffstat (limited to 'src/librustpkg/path_util.rs')
| -rw-r--r-- | src/librustpkg/path_util.rs | 44 | 
1 files changed, 5 insertions, 39 deletions
| diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index a8931e52747..0ebc33cf5bc 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -14,6 +14,7 @@ use core::path::*; use core::{os, str}; use core::option::*; use util::PkgId; +use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; #[deriving(Eq)] pub enum OutputType { Main, Lib, Bench, Test } @@ -25,34 +26,15 @@ pub fn rust_path() -> ~[Path] { ~[Path(".")] } +static u_rwx: i32 = (S_IRUSR | S_IWUSR | S_IXUSR) as i32; + /// Creates a directory that is readable, writeable, /// and executable by the user. Returns true iff creation /// succeeded. pub fn make_dir_rwx(p: &Path) -> bool { use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; - os::make_dir(p, (S_IRUSR | S_IWUSR | S_IXUSR) as i32) -} - -/// Creates a directory that is readable, writeable, -/// and executable by the user. Returns true iff creation -/// succeeded. Also creates all intermediate subdirectories -/// if they don't already exist. -pub fn mkdir_recursive(p: &Path) -> bool { - if os::path_is_dir(p) { - return true; - } - let parent = p.dir_path(); - debug!("mkdir_recursive: parent = %s", - parent.to_str()); - if parent.to_str() == ~"." - || parent.to_str() == ~"/" { // !!! - // No parent directories to create - os::path_is_dir(&parent) && make_dir_rwx(p) - } - else { - mkdir_recursive(&parent) && make_dir_rwx(p) - } + os::make_dir(p, u_rwx) } /// Replace all occurrences of '-' in the stem part of path with '_' @@ -130,7 +112,7 @@ pub fn build_pkg_id_in_workspace(pkgid: PkgId, workspace: &Path) -> Path { // n.b. Should actually use a target-specific // subdirectory of build/ result = result.push(normalize(~pkgid.path).to_str()); - if os::path_exists(&result) || mkdir_recursive(&result) { + if os::path_exists(&result) || os::mkdir_recursive(&result, u_rwx) { result } else { @@ -148,19 +130,3 @@ pub fn mk_output_path(what: OutputType, short_name: ~str, dir: Path) -> Path { os::EXE_SUFFIX)) } } - -#[cfg(test)] -mod test { - use core::os; - - #[test] - fn recursive_mkdir_ok() { - let root = os::tmpdir(); - let path = "xy/z/zy"; - let nested = root.push(path); - assert!(super::mkdir_recursive(&nested)); - assert!(os::path_is_dir(&root.push("xy"))); - assert!(os::path_is_dir(&root.push("xy/z"))); - assert!(os::path_is_dir(&nested)); - } -} | 
