Skip to content

Truly independent web browser

LibFileSystem: Copy files in chunks in copy_file()

Andreas Kling27ffde27f1c3
diff --git a/Libraries/LibFileSystem/FileSystem.cpp b/Libraries/LibFileSystem/FileSystem.cpp
index 29887dac64e..e6a919560c7 100644
--- a/Libraries/LibFileSystem/FileSystem.cpp
+++ b/Libraries/LibFileSystem/FileSystem.cpp
@@ -227,13 +227,12 @@ ErrorOr<void> copy_file(StringView destination_path, StringView source_path, str
if (source_stat.st_size > 0)
TRY(destination->truncate(source_stat.st_size));
+ Array<u8, 64 * KiB> buffer;
while (true) {
- auto bytes_read = TRY(source.read_until_eof());
-
- if (bytes_read.is_empty())
+ auto bytes = TRY(source.read_some(buffer));
+ if (bytes.is_empty())
break;
-
- TRY(destination->write_until_depleted(bytes_read));
+ TRY(destination->write_until_depleted(bytes));
}
auto my_umask = umask(0);