Skip to content

Commit acde573

Browse files
authored
os: fix mv_by_cp for directories (#20154)
1 parent 423b34f commit acde573

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

vlib/os/os.v

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,15 @@ pub fn cp_all(src string, dst string, overwrite bool) ! {
119119
}
120120
}
121121

122-
// mv_by_cp first copies the source file, and if it is copied successfully, deletes the source file.
123-
// may be used when you are not sure that the source and target are on the same mount/partition.
122+
// mv_by_cp copies files or folders from `source` to `target`.
123+
// If copying is successful, `source` is deleted.
124+
// It may be used when the paths are not on the same mount/partition.
124125
pub fn mv_by_cp(source string, target string) ! {
125-
cp(source, target)!
126+
cp_all(source, target, true)!
127+
if is_dir(source) {
128+
rmdir_all(source)!
129+
return
130+
}
126131
rm(source)!
127132
}
128133

0 commit comments

Comments
 (0)