1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: make rm return an optional

This commit is contained in:
Lukas Neubert 2020-06-24 14:01:19 +02:00 committed by GitHub
parent 7665114ded
commit 30169f86c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -291,7 +291,7 @@ fn C._putenv() int
fn C._waccess() int
fn C._wremove()
fn C._wremove() int
fn C.ReadConsole() voidptr

View File

@ -628,12 +628,21 @@ pub fn file_exists(_path string) bool {
}
// rm removes file in `path`.
pub fn rm(path string) {
pub fn rm(path string) ? {
$if windows {
C._wremove(path.to_wide())
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"')
}
} $else {
C.remove(path.str)
rc := C.remove(path.str)
if rc == -1 {
return error(posix_get_error_msg(C.errno))
}
}
return
// C.unlink(path.cstr())
}
// rmdir removes a specified directory.