mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix cp_all mkdir panic (#8680)
This commit is contained in:
parent
375efb0953
commit
65f2420516
@ -62,7 +62,9 @@ pub fn cp_all(src string, dst string, overwrite bool) ? {
|
|||||||
sp := join_path(source_path, file)
|
sp := join_path(source_path, file)
|
||||||
dp := join_path(dest_path, file)
|
dp := join_path(dest_path, file)
|
||||||
if is_dir(sp) {
|
if is_dir(sp) {
|
||||||
mkdir(dp) ?
|
if !exists(dp) {
|
||||||
|
mkdir(dp) ?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cp_all(sp, dp, overwrite) or {
|
cp_all(sp, dp, overwrite) or {
|
||||||
rmdir(dp) or { return error(err) }
|
rmdir(dp) or { return error(err) }
|
||||||
|
@ -250,7 +250,7 @@ fn test_mv() {
|
|||||||
assert os.exists(expected) && !is_dir(expected) == true
|
assert os.exists(expected) && !is_dir(expected) == true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_cp_r() {
|
fn test_cp_all() {
|
||||||
// fileX -> dir/fileX
|
// fileX -> dir/fileX
|
||||||
// NB: clean up of the files happens inside the cleanup_leftovers function
|
// NB: clean up of the files happens inside the cleanup_leftovers function
|
||||||
os.write_file('ex1.txt', 'wow!') or { panic(err) }
|
os.write_file('ex1.txt', 'wow!') or { panic(err) }
|
||||||
@ -267,6 +267,8 @@ fn test_cp_r() {
|
|||||||
assert old2 == new2
|
assert old2 == new2
|
||||||
// recurring on dir -> local dir
|
// recurring on dir -> local dir
|
||||||
os.cp_all('ex', './', true) or { panic(err) }
|
os.cp_all('ex', './', true) or { panic(err) }
|
||||||
|
// regression test for executive runs with overwrite := true
|
||||||
|
os.cp_all('ex', './', true) or { panic(err) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_tmpdir() {
|
fn test_tmpdir() {
|
||||||
@ -274,7 +276,7 @@ fn test_tmpdir() {
|
|||||||
assert t.len > 0
|
assert t.len > 0
|
||||||
assert os.is_dir(t)
|
assert os.is_dir(t)
|
||||||
tfile := t + os.path_separator + 'tmpfile.txt'
|
tfile := t + os.path_separator + 'tmpfile.txt'
|
||||||
os.rm(tfile) or { } // just in case
|
os.rm(tfile) or { } // just in case
|
||||||
tfile_content := 'this is a temporary file'
|
tfile_content := 'this is a temporary file'
|
||||||
os.write_file(tfile, tfile_content) or { panic(err) }
|
os.write_file(tfile, tfile_content) or { panic(err) }
|
||||||
tfile_content_read := os.read_file(tfile) or { panic(err) }
|
tfile_content_read := os.read_file(tfile) or { panic(err) }
|
||||||
|
Loading…
Reference in New Issue
Block a user