diff options
| author | gingerBill <bill@gingerbill.org> | 2025-04-25 09:01:53 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2025-04-25 09:01:53 +0100 |
| commit | f3cc734b392b2188b8dac685fd202dbbef6ea01b (patch) | |
| tree | f7001e9c427663cb12a808792711a43c159bc5f4 /core/os | |
| parent | b5c658a2cfe3bcbe3534a6c169ec45f5acc3adc4 (diff) | |
Add `copy_directory`
Diffstat (limited to 'core/os')
| -rw-r--r-- | core/os/os2/dir.odin | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/os/os2/dir.odin b/core/os/os2/dir.odin index 4a7762ded..9e6eaab72 100644 --- a/core/os/os2/dir.odin +++ b/core/os/os2/dir.odin @@ -192,3 +192,30 @@ read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info, return _read_directory_iterator(it) } + +// Recursively copies a directory to `dst` from `src` +copy_directory :: proc(dst, src: string, dst_perm := 0o755) -> Error { + switch err := make_directory_all(dst, dst_perm); err { + case nil, .Exist: + // okay + case: + return err + } + + TEMP_ALLOCATOR_GUARD() + + file_infos := read_all_directory_by_path(src, temp_allocator()) or_return + for fi in file_infos { + TEMP_ALLOCATOR_GUARD() + + dst_path := join_path({dst, fi.name}, temp_allocator()) or_return + src_path := fi.fullpath + + if fi.type == .Directory { + copy_directory(dst_path, src_path) or_return + } else { + copy_file(dst_path, src_path) or_return + } + } + return nil +}
\ No newline at end of file |