os: change os.mv/2 return type to `?` (#7738)

pull/7739/head
yuyi 2020-12-31 17:33:39 +08:00 committed by GitHub
parent 64e7c54884
commit 7ce3c5e206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -235,7 +235,7 @@ fn C.WideCharToMultiByte() int
fn C._wstat() fn C._wstat()
fn C._wrename() fn C._wrename() int
fn C._wfopen() voidptr fn C._wfopen() voidptr

View File

@ -114,7 +114,7 @@ pub fn file_size(path string) int {
} }
// mv moves files or folders from `src` to `dst`. // 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 mut rdst := dst
if is_dir(rdst) { if is_dir(rdst) {
rdst = join_path(rdst.trim_right(path_separator), file_name(src.trim_right(path_separator))) 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 { $if windows {
w_src := src.replace('/', '\\') w_src := src.replace('/', '\\')
w_dst := rdst.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 { } $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))
}
} }
} }