Skip to content

Commit

Permalink
os: fix mv_by_cp for directories (#20154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Dec 11, 2023
1 parent 423b34f commit acde573
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions vlib/os/os.v
Expand Up @@ -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)!
}

Expand Down

0 comments on commit acde573

Please sign in to comment.