File tree Expand file tree Collapse file tree 8 files changed +54
-2
lines changed Expand file tree Collapse file tree 8 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: d468af59ede45140fa531992829b30ecd9d57cc1
2
+ refs/heads/master: 9dd4789d80b1313bb39daa8c8973e63a60b07b94
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ fn file_is_dir(p: path) -> bool {
119
119
/*
120
120
Function: make_dir
121
121
122
- Creates a directory at the specific path.
122
+ Creates a directory at the specified path.
123
123
*/
124
124
fn make_dir ( p : path , mode : int ) -> bool {
125
125
ret mkdir ( p, mode) ;
@@ -157,6 +157,26 @@ fn list_dir(p: path) -> [str] {
157
157
ret full_paths;
158
158
}
159
159
160
+ /*
161
+ Function: remove_dir
162
+
163
+ Removes a directory at the specified path.
164
+ */
165
+ fn remove_dir ( p : path ) -> bool {
166
+ ret rmdir ( p) ;
167
+
168
+ #[ cfg( target_os = "win32" ) ]
169
+ fn rmdir ( _p : path ) -> bool {
170
+ ret str:: as_buf ( _p, { |buf| os:: kernel32:: RemoveDirectory ( buf) } ) ;
171
+ }
172
+
173
+ #[ cfg( target_os = "linux" ) ]
174
+ #[ cfg( target_os = "macos" ) ]
175
+ fn rmdir ( _p : path ) -> bool {
176
+ ret str:: as_buf ( _p, { |buf| os:: libc:: rmdir ( buf) == 0 } ) ;
177
+ }
178
+ }
179
+
160
180
/*
161
181
Function: path_is_absolute
162
182
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ native mod libc {
52
52
fn waitpid ( pid : pid_t , & status: c_int , options : c_int ) -> pid_t ;
53
53
fn readlink ( path : str:: sbuf , buf : str:: sbuf , bufsize : size_t ) -> ssize_t ;
54
54
fn mkdir ( path : str:: sbuf , mode : int ) -> int ;
55
+ fn rmdir ( path : str:: sbuf ) -> int ;
55
56
}
56
57
57
58
mod libc_constants {
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ native mod libc {
45
45
fn pipe ( buf : * mutable int ) -> int ;
46
46
fn waitpid ( pid : int , & status: int , options : int ) -> int ;
47
47
fn mkdir ( s : str:: sbuf , mode : int ) -> int ;
48
+ fn rmdir ( s : str:: sbuf ) -> int ;
48
49
}
49
50
50
51
mod libc_constants {
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ native mod kernel32 {
54
54
nSize : DWORD ) -> DWORD ;
55
55
fn CreateDirectory ( lpPathName : LPCTSTR ,
56
56
lpSecurityAttributes : LPSECURITY_ATTRIBUTES ) -> bool ;
57
+ fn RemoveDirectory ( lpPathName : LPCTSTR ) -> bool ;
57
58
}
58
59
59
60
// FIXME turn into constants
Original file line number Diff line number Diff line change 3
3
// -*- rust -*-
4
4
use std;
5
5
import std:: rand;
6
+ import std:: str;
6
7
7
8
#[ test]
8
9
fn test ( ) {
@@ -27,3 +28,13 @@ fn test() {
27
28
log r1. next ( ) ;
28
29
log r1. next ( ) ;
29
30
}
31
+
32
+ #[ test]
33
+ fn genstr ( ) {
34
+ let r: rand:: rng = rand:: mk_rng ( ) ;
35
+ log r. gen_str ( 10 u) ;
36
+ log r. gen_str ( 10 u) ;
37
+ log r. gen_str ( 10 u) ;
38
+ assert ( str:: char_len ( r. gen_str ( 10 u) ) == 10 u) ;
39
+ assert ( str:: char_len ( r. gen_str ( 16 u) ) == 16 u) ;
40
+ }
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ mod sort;
33
33
mod str;
34
34
mod sys;
35
35
mod task;
36
+ mod tempfile;
36
37
mod test;
37
38
mod tri;
38
39
mod treemap;
Original file line number Diff line number Diff line change
1
+ use std;
2
+ import std:: fs;
3
+ import std:: option:: some;
4
+ import std:: str;
5
+ import std:: tempfile;
6
+
7
+ #[ test]
8
+ fn mkdtemp ( ) {
9
+ let r = tempfile:: mkdtemp ( "./" , "foobar" ) ;
10
+ alt r {
11
+ some( p) {
12
+ fs:: remove_dir ( p) ;
13
+ assert ( str:: ends_with ( p, "foobar" ) ) ;
14
+ }
15
+ _ { assert( false ) ; }
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments