From 51d7d7cfae70141d563fb48b172cc8d3eee83676 Mon Sep 17 00:00:00 2001 From: Larpon Date: Sun, 6 Sep 2020 13:12:07 +0200 Subject: [PATCH] os: fix os.mv edge case and Windows style paths (#6302) --- vlib/os/os.v | 6 ++++-- vlib/os/os_test.v | 9 ++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/vlib/os/os.v b/vlib/os/os.v index 195d74626b..2e69851944 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -60,10 +60,12 @@ pub fn file_size(path string) int { pub fn mv(src, dst string) { mut rdst := dst if is_dir(rdst) { - rdst = join_path(rdst,file_name(src.trim_right(path_separator))) + rdst = join_path(rdst.trim_right(path_separator),file_name(src.trim_right(path_separator))) } $if windows { - C._wrename(src.to_wide(), rdst.to_wide()) + w_src := src.replace('/', '\\') + w_dst := rdst.replace('/', '\\') + C._wrename(w_src.to_wide(), w_dst.to_wide()) } $else { C.rename(charptr(src.str), charptr(rdst.str)) } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index bc450aaead..535b86b88d 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -186,13 +186,9 @@ fn test_cp() { os.rm(new_file_name) } -/* fn test_mv() { - work_dir := os.join_path(os.temp_dir(),'v','mv_test') - if os.exists(work_dir) { - os.rmdir_all(work_dir) - } - mkdir_all(work_dir) + work_dir := os.join_path(os.getwd(),'mv_test') + os.mkdir_all(work_dir) // Setup test files tfile1 := os.join_path(work_dir,'file') tfile2 := os.join_path(work_dir,'file.test') @@ -230,7 +226,6 @@ fn test_mv() { expected = tfile3 assert os.exists(expected) && !is_dir(expected) == true } -*/ fn test_cp_r() { // fileX -> dir/fileX