From e99b699ac6ecfc35dff064a5b045cc372327353d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 24 Oct 2021 19:16:46 +0300 Subject: [PATCH] os: make os.mkdir_all more robust (honor / on windows too), add a test for it --- vlib/os/os.v | 3 ++- vlib/os/os_test.v | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/vlib/os/os.v b/vlib/os/os.v index 82692ed255..a7d09625a9 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -535,7 +535,8 @@ pub fn log(s string) { } // mkdir_all will create a valid full path of all directories given in `path`. -pub fn mkdir_all(path string) ? { +pub fn mkdir_all(opath string) ? { + path := opath.replace('/', path_separator) mut p := if path.starts_with(path_separator) { path_separator } else { '' } path_parts := path.trim_left(path_separator).split(path_separator) for subdir in path_parts { diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 7cdca800c9..26bea76805 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -201,6 +201,8 @@ fn test_ls() { fn create_tree() ? { os.mkdir_all('myfolder/f1/f2/f3') ? os.mkdir_all('myfolder/a1/a2/a3') ? + f3 := os.real_path('myfolder/f1/f2/f3') + assert os.is_dir(f3) create_file('myfolder/f1/f2/f3/a.txt') ? create_file('myfolder/f1/f2/f3/b.txt') ? create_file('myfolder/f1/f2/f3/c.txt') ?