File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -695,6 +695,12 @@ pub struct MkdirParams {
695695
696696// mkdir_all will create a valid full path of all directories given in `path`.
697697pub fn mkdir_all (opath string , params MkdirParams) ! {
698+ if exists (opath) {
699+ if is_dir (opath) {
700+ return
701+ }
702+ return error ('path `${opath} ` already exists, and is not a folder' )
703+ }
698704 other_separator := if path_separator == '/' { '\\ ' } else { '/' }
699705 path := opath.replace (other_separator, path_separator)
700706 mut p := if path.starts_with (path_separator) { path_separator } else { '' }
Original file line number Diff line number Diff line change @@ -1016,3 +1016,17 @@ fn test_mv_across_partitions() {
10161016fn test_page_size () {
10171017 assert os.page_size () > = 4096 // this is normal and assumed.
10181018}
1019+
1020+ fn test_mkdir_at_file_dst () {
1021+ f3 := os.join_path ('myfolder' , 'f1' , 'f2' , 'f3' )
1022+ os.mkdir_all (f3 )!
1023+ assert os.is_dir (f3 )
1024+ path := os.join_path (f3 , 'no_ext_doc' )
1025+ os.write_file (path, '' )!
1026+ assert os.exists (path) && os.is_file (path)
1027+ os.mkdir_all (path) or {
1028+ assert err.msg () == 'path `${path} ` already exists, and is not a folder' , err.msg ()
1029+ return
1030+ }
1031+ assert false
1032+ }
You can’t perform that action at this time.
0 commit comments