mirror of
https://github.com/vlang/v.git
synced 2025-09-12 17:07:11 -04:00
os: add fast path to mkdir_all, when the given folder already exists (#19869)
This commit is contained in:
parent
b5673c6172
commit
b7400fc058
@ -695,6 +695,12 @@ pub struct MkdirParams {
|
||||
|
||||
// mkdir_all will create a valid full path of all directories given in `path`.
|
||||
pub fn mkdir_all(opath string, params MkdirParams) ! {
|
||||
if exists(opath) {
|
||||
if is_dir(opath) {
|
||||
return
|
||||
}
|
||||
return error('path `${opath}` already exists, and is not a folder')
|
||||
}
|
||||
other_separator := if path_separator == '/' { '\\' } else { '/' }
|
||||
path := opath.replace(other_separator, path_separator)
|
||||
mut p := if path.starts_with(path_separator) { path_separator } else { '' }
|
||||
|
@ -1016,3 +1016,17 @@ fn test_mv_across_partitions() {
|
||||
fn test_page_size() {
|
||||
assert os.page_size() >= 4096 // this is normal and assumed.
|
||||
}
|
||||
|
||||
fn test_mkdir_at_file_dst() {
|
||||
f3 := os.join_path('myfolder', 'f1', 'f2', 'f3')
|
||||
os.mkdir_all(f3)!
|
||||
assert os.is_dir(f3)
|
||||
path := os.join_path(f3, 'no_ext_doc')
|
||||
os.write_file(path, '')!
|
||||
assert os.exists(path) && os.is_file(path)
|
||||
os.mkdir_all(path) or {
|
||||
assert err.msg() == 'path `${path}` already exists, and is not a folder', err.msg()
|
||||
return
|
||||
}
|
||||
assert false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user