From c83c5e7c61d9f2ae4d64d34ad16877a9a0a41dec Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 26 Jun 2020 17:56:34 +0300 Subject: [PATCH] os: use `return none` in functions returning `?` --- vlib/os/os.v | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/vlib/os/os.v b/vlib/os/os.v index 519b9a7e99..c64b282a3e 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -196,7 +196,7 @@ pub fn cp(old, new string) ? { return error_with_code('failed to set permissions for $new', int(-1)) } } - return + return none } [deprecated] @@ -225,7 +225,7 @@ pub fn cp_all(osource_path, odest_path string, overwrite bool) ? { os.cp(source_path, adjusted_path) or { return error(err) } - return + return none } if !os.is_dir(dest_path) { return error('Destination path is not a valid directory') @@ -246,7 +246,7 @@ pub fn cp_all(osource_path, odest_path string, overwrite bool) ? { panic(err) } } - return + return none } // mv_by_cp first copies the source file, and if it is copied successfully, deletes the source file. @@ -258,7 +258,7 @@ pub fn mv_by_cp(source string, target string) ? { os.rm(source) or { return error(err) } - return + return none } // vfopen returns an opened C file, given its path and open mode. @@ -638,23 +638,24 @@ pub fn rm(path string) ? { return error(posix_get_error_msg(C.errno)) } } - - return + return none // C.unlink(path.cstr()) } // rmdir removes a specified directory. pub fn rmdir(path string) ? { - $if !windows { + $if windows { + rc := C.RemoveDirectory(path.to_wide()) + if rc == 0 { + // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya - 0 is failure + return error('Failed to remove "$path"') + } + } $else { rc := C.rmdir(path.str) if rc == -1 { return error(posix_get_error_msg(C.errno)) } - } $else { - rc := C.RemoveDirectory(path.to_wide()) - if rc == 0 { - return error('Failed to remove "$path"') - } } + return none } [deprecated] @@ -666,7 +667,7 @@ pub fn rmdir_recursive(path string) { pub fn rmdir_all(path string) ? { mut ret_err := '' items := os.ls(path) or { - return + return none } for item in items { if os.is_dir(os.join_path(path, item)) { @@ -678,6 +679,7 @@ pub fn rmdir_all(path string) ? { if ret_err.len > 0 { return error(ret_err) } + return none } pub fn is_dir_empty(path string) bool {