From d03c1d615ae46f0d777e55cf05d834e9e3174e1e Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 13 Feb 2021 12:51:38 +0000 Subject: [PATCH] os: improve `rm` error message (#8719) --- vlib/os/os_c.v | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/vlib/os/os_c.v b/vlib/os/os_c.v index 34a6074ddd..82b544d26a 100644 --- a/vlib/os/os_c.v +++ b/vlib/os/os_c.v @@ -432,17 +432,14 @@ pub fn is_readable(path string) bool { // rm removes file in `path`. pub fn rm(path string) ? { + mut rc := 0 $if windows { - rc := C._wremove(path.to_wide()) - if rc == -1 { - // TODO: proper error as soon as it's supported on windows - return error('Failed to remove "$path"') - } + rc = C._wremove(path.to_wide()) } $else { - rc := C.remove(charptr(path.str)) - if rc == -1 { - return error(posix_get_error_msg(C.errno)) - } + rc = C.remove(charptr(path.str)) + } + if rc == -1 { + return error('Failed to remove "$path": ' + posix_get_error_msg(C.errno)) } // C.unlink(path.cstr()) }