From 7ce3c5e2069b980731b2b281d2bd2111ffbf8f43 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 31 Dec 2020 17:33:39 +0800 Subject: [PATCH] os: change os.mv/2 return type to `?` (#7738) --- vlib/builtin/cfns.c.v | 2 +- vlib/os/os_c.v | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index 7e5b06dc81..4f22e1e7f6 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -235,7 +235,7 @@ fn C.WideCharToMultiByte() int fn C._wstat() -fn C._wrename() +fn C._wrename() int fn C._wfopen() voidptr diff --git a/vlib/os/os_c.v b/vlib/os/os_c.v index d006096f21..f457b82ae8 100644 --- a/vlib/os/os_c.v +++ b/vlib/os/os_c.v @@ -114,7 +114,7 @@ pub fn file_size(path string) int { } // mv moves files or folders from `src` to `dst`. -pub fn mv(src string, dst string) { +pub fn mv(src string, dst string) ? { mut rdst := dst if is_dir(rdst) { rdst = join_path(rdst.trim_right(path_separator), file_name(src.trim_right(path_separator))) @@ -122,9 +122,15 @@ pub fn mv(src string, dst string) { $if windows { w_src := src.replace('/', '\\') w_dst := rdst.replace('/', '\\') - C._wrename(w_src.to_wide(), w_dst.to_wide()) + ret := C._wrename(w_src.to_wide(), w_dst.to_wide()) + if ret != 0 { + return error_with_code('failed to rename $src to $dst', int(ret)) + } } $else { - C.rename(charptr(src.str), charptr(rdst.str)) + ret := C.rename(charptr(src.str), charptr(rdst.str)) + if ret != 0 { + return error_with_code('failed to rename $src to $dst', int(ret)) + } } }