| ... | ... | @@ -413,3 +413,24 @@ pub fn existsDir(self: Dir, sub_path: [:0]const u8) !bool { |
| 413 | 413 | dir.close(); |
| 414 | 414 | return true; |
| 415 | 415 | } |
| 416 | |
| 417 | pub fn copyFile(source_dir: Dir, source_path: [:0]const u8, dest_dir: Dir, dest_path: [:0]const u8) !void { |
| 418 | const source_file = try source_dir.openFile(source_path, .{}); |
| 419 | defer source_file.close(); |
| 420 | const source_stat = try source_file.stat(); |
| 421 | |
| 422 | const dest_file = try dest_dir.createFile(dest_path, .{ .exclusive = true }); |
| 423 | defer dest_file.close(); |
| 424 | |
| 425 | if (os == .linux) { |
| 426 | var off: u64 = 0; |
| 427 | var off_in: sys.off_t = 0; |
| 428 | var off_out: sys.off_t = 0; |
| 429 | while (true) { |
| 430 | const amt = try sys.copy_file_range(@intFromEnum(source_file.fd), &off_in, @intFromEnum(dest_file.fd), &off_out, source_stat.size - off, 0); |
| 431 | off += amt; |
| 432 | if (amt == 0) break; |
| 433 | } |
| 434 | return; |
| 435 | } |
| 436 | } |