os: fix os.cp_all, by making the dst folder, if it does not exist already
parent
e229d0c1c3
commit
995db65471
|
@ -48,6 +48,9 @@ pub fn cp_all(src string, dst string, overwrite bool) ? {
|
|||
cp(source_path, adjusted_path) ?
|
||||
return
|
||||
}
|
||||
if !exists(dest_path) {
|
||||
mkdir(dest_path) ?
|
||||
}
|
||||
if !is_dir(dest_path) {
|
||||
return error('Destination path is not a valid directory')
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ fn test_open_file_binary() {
|
|||
}
|
||||
mut file := os.open_file(filename, 'wb+', 0o666) or { panic(err) }
|
||||
bytes := hello.bytes()
|
||||
file.write_bytes(bytes.data, bytes.len)
|
||||
unsafe { file.write_bytes(bytes.data, bytes.len) }
|
||||
file.close()
|
||||
assert hello.len == os.file_size(filename)
|
||||
read_hello := os.read_bytes(filename) or { panic('error reading file $filename') }
|
||||
|
@ -144,7 +144,7 @@ fn test_write_and_read_bytes() {
|
|||
}
|
||||
// We use the standard write_bytes function to write the payload and
|
||||
// compare the length of the array with the file size (have to match).
|
||||
file_write.write_bytes(payload.data, 5)
|
||||
unsafe { file_write.write_bytes(payload.data, 5) }
|
||||
file_write.close()
|
||||
assert payload.len == os.file_size(file_name)
|
||||
mut file_read := os.open(os.real_path(file_name)) or {
|
||||
|
@ -269,6 +269,8 @@ fn test_cp_all() {
|
|||
os.cp_all('ex', './', true) or { panic(err) }
|
||||
// regression test for executive runs with overwrite := true
|
||||
os.cp_all('ex', './', true) or { panic(err) }
|
||||
os.cp_all('ex', 'nonexisting', true) or { panic(err) }
|
||||
assert os.exists(os.join_path('nonexisting', 'ex1.txt'))
|
||||
}
|
||||
|
||||
fn test_realpath() {
|
||||
|
|
Loading…
Reference in New Issue