@@ -14,6 +14,7 @@ use core::path::*;
1414use core:: { os, str} ;
1515use core:: option:: * ;
1616use util:: PkgId ;
17+ use core:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
1718
1819#[ deriving( Eq ) ]
1920pub enum OutputType { Main , Lib , Bench , Test }
@@ -25,34 +26,15 @@ pub fn rust_path() -> ~[Path] {
2526 ~[ Path ( "." ) ]
2627}
2728
29+ static u_rwx: i32 = ( S_IRUSR | S_IWUSR | S_IXUSR ) as i32 ;
30+
2831/// Creates a directory that is readable, writeable,
2932/// and executable by the user. Returns true iff creation
3033/// succeeded.
3134pub fn make_dir_rwx ( p : & Path ) -> bool {
3235 use core:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
3336
34- os:: make_dir ( p, ( S_IRUSR | S_IWUSR | S_IXUSR ) as i32 )
35- }
36-
37- /// Creates a directory that is readable, writeable,
38- /// and executable by the user. Returns true iff creation
39- /// succeeded. Also creates all intermediate subdirectories
40- /// if they don't already exist.
41- pub fn mkdir_recursive ( p : & Path ) -> bool {
42- if os:: path_is_dir ( p) {
43- return true ;
44- }
45- let parent = p. dir_path ( ) ;
46- debug ! ( "mkdir_recursive: parent = %s" ,
47- parent. to_str( ) ) ;
48- if parent. to_str ( ) == ~". "
49- || parent. to_str ( ) == ~"/" { // !!!
50- // No parent directories to create
51- os:: path_is_dir ( & parent) && make_dir_rwx ( p)
52- }
53- else {
54- mkdir_recursive ( & parent) && make_dir_rwx ( p)
55- }
37+ os:: make_dir ( p, u_rwx)
5638}
5739
5840/// 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 {
130112 // n.b. Should actually use a target-specific
131113 // subdirectory of build/
132114 result = result. push ( normalize ( ~pkgid. path ) . to_str ( ) ) ;
133- if os:: path_exists ( & result) || mkdir_recursive ( & result) {
115+ if os:: path_exists ( & result) || os :: mkdir_recursive ( & result, u_rwx ) {
134116 result
135117 }
136118 else {
@@ -148,19 +130,3 @@ pub fn mk_output_path(what: OutputType, short_name: ~str, dir: Path) -> Path {
148130 os:: EXE_SUFFIX ) )
149131 }
150132}
151-
152- #[cfg(test)]
153- mod test {
154- use core::os;
155-
156- #[test]
157- fn recursive_mkdir_ok() {
158- let root = os::tmpdir();
159- let path = " xy/z/zy";
160- let nested = root.push(path);
161- assert!(super::mkdir_recursive(&nested));
162- assert!(os::path_is_dir(&root.push(" xy")));
163- assert!(os::path_is_dir(&root.push(" xy/z") ) ) ;
164- assert!( os:: path_is_dir( & nested) ) ;
165- }
166- }
0 commit comments