diff --git a/vlib/os/os.v b/vlib/os/os.v index 9f71f74da2acf9..af7e73ed74e72c 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -119,10 +119,15 @@ pub fn cp_all(src string, dst string, overwrite bool) ! { } } -// mv_by_cp first copies the source file, and if it is copied successfully, deletes the source file. -// may be used when you are not sure that the source and target are on the same mount/partition. +// mv_by_cp copies files or folders from `source` to `target`. +// If copying is successful, `source` is deleted. +// It may be used when the paths are not on the same mount/partition. pub fn mv_by_cp(source string, target string) ! { - cp(source, target)! + cp_all(source, target, true)! + if is_dir(source) { + rmdir_all(source)! + return + } rm(source)! }