From a620e66af500d3e7172c509a7ea6c83b772406bd Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 19 Nov 2019 11:55:03 +0200 Subject: [PATCH] compiler: add os.mv_by_cp and use it for the temporary files --- tools/vup.v | 2 +- vlib/compiler/cc.v | 4 +++- vlib/os/os.v | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/vup.v b/tools/vup.v index 78ceadeef5..fd156e4b90 100644 --- a/tools/vup.v +++ b/tools/vup.v @@ -11,7 +11,7 @@ fn main() { if os.file_exists( v_backup_file ) { os.rm( v_backup_file ) } - os.mv('$vroot/v.exe', v_backup_file) + os.mv_by_cp('$vroot/v.exe', v_backup_file) or { panic(err) } s2 := os.exec('"$vroot/make.bat"') or { panic(err) } println(s2.output) } $else { diff --git a/vlib/compiler/cc.v b/vlib/compiler/cc.v index cc32a10e85..ddecef9e51 100644 --- a/vlib/compiler/cc.v +++ b/vlib/compiler/cc.v @@ -57,7 +57,9 @@ fn (v mut V) cc() { } } } - os.mv(v.out_name_c, v.out_name) + + // v.out_name_c may be on a different partition than v.out_name + os.mv_by_cp(v.out_name_c, v.out_name) or { panic(err) } exit(0) } // Cross compiling for Windows diff --git a/vlib/os/os.v b/vlib/os/os.v index df8487bdad..e9e18e1ecf 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -187,6 +187,14 @@ pub fn cp_r(osource_path, odest_path string, overwrite bool) ?bool{ return true } +// mv_by_cp first copies the source file, and if it is copied successfully, deletes the source file. +// mv_by_cp may be used when you are not sure that the source and target are on the same mount/partition. +pub fn mv_by_cp(source string, target string) ?bool { + os.cp(source, target) or { return error(err) } + os.rm(source) + return true +} + fn vfopen(path, mode string) *C.FILE { $if windows { return C._wfopen(path.to_wide(), mode.to_wide())