@@ -165,8 +165,10 @@ pub fn mkdir(path: &Path, recursive: bool, mode: u32, verbose: bool) -> UResult<
165
165
let path_buf = dir_strip_dot_for_creation ( path) ;
166
166
let path = path_buf. as_path ( ) ;
167
167
168
- create_dir ( path, recursive, verbose, false ) ?;
169
- chmod ( path, mode)
168
+ if create_dir ( path, recursive, verbose, false ) ? {
169
+ chmod ( path, mode) ?;
170
+ }
171
+ Ok ( ( ) )
170
172
}
171
173
172
174
#[ cfg( any( unix, target_os = "redox" ) ) ]
@@ -186,22 +188,25 @@ fn chmod(_path: &Path, _mode: u32) -> UResult<()> {
186
188
Ok ( ( ) )
187
189
}
188
190
191
+ // Return true if the directory at `path` has been created by this call.
189
192
// `is_parent` argument is not used on windows
190
193
#[ allow( unused_variables) ]
191
- fn create_dir ( path : & Path , recursive : bool , verbose : bool , is_parent : bool ) -> UResult < ( ) > {
194
+ fn create_dir ( path : & Path , recursive : bool , verbose : bool , is_parent : bool ) -> UResult < bool > {
192
195
if path. exists ( ) && !recursive {
193
196
return Err ( USimpleError :: new (
194
197
1 ,
195
198
format ! ( "{}: File exists" , path. display( ) ) ,
196
199
) ) ;
197
200
}
198
201
if path == Path :: new ( "" ) {
199
- return Ok ( ( ) ) ;
202
+ return Ok ( false ) ;
200
203
}
201
204
202
205
if recursive {
203
206
match path. parent ( ) {
204
- Some ( p) => create_dir ( p, recursive, verbose, true ) ?,
207
+ Some ( p) => {
208
+ create_dir ( p, recursive, verbose, true ) ?;
209
+ }
205
210
None => {
206
211
USimpleError :: new ( 1 , "failed to create whole tree" ) ;
207
212
}
@@ -222,9 +227,9 @@ fn create_dir(path: &Path, recursive: bool, verbose: bool, is_parent: bool) -> U
222
227
// which is umask modified by 'u+wx'
223
228
chmod ( path, ( !mode:: get_umask ( ) & 0o0777 ) | 0o0300 ) ?;
224
229
}
225
- Ok ( ( ) )
230
+ Ok ( true )
226
231
}
227
- Err ( _) if path. is_dir ( ) => Ok ( ( ) ) ,
232
+ Err ( _) if path. is_dir ( ) => Ok ( false ) ,
228
233
Err ( e) => Err ( e. into ( ) ) ,
229
234
}
230
235
}
0 commit comments