@@ -14,6 +14,7 @@ use core::path::*;
14
14
use core:: { os, str} ;
15
15
use core:: option:: * ;
16
16
use util:: PkgId ;
17
+ use core:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
17
18
18
19
#[ deriving( Eq ) ]
19
20
pub enum OutputType { Main , Lib , Bench , Test }
@@ -25,34 +26,15 @@ pub fn rust_path() -> ~[Path] {
25
26
~[ Path ( "." ) ]
26
27
}
27
28
29
+ static u_rwx: i32 = ( S_IRUSR | S_IWUSR | S_IXUSR ) as i32 ;
30
+
28
31
/// Creates a directory that is readable, writeable,
29
32
/// and executable by the user. Returns true iff creation
30
33
/// succeeded.
31
34
pub fn make_dir_rwx ( p : & Path ) -> bool {
32
35
use core:: libc:: consts:: os:: posix88:: { S_IRUSR , S_IWUSR , S_IXUSR } ;
33
36
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)
56
38
}
57
39
58
40
/// 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 {
130
112
// n.b. Should actually use a target-specific
131
113
// subdirectory of build/
132
114
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 ) {
134
116
result
135
117
}
136
118
else {
@@ -148,19 +130,3 @@ pub fn mk_output_path(what: OutputType, short_name: ~str, dir: Path) -> Path {
148
130
os:: EXE_SUFFIX ) )
149
131
}
150
132
}
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