mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
FileManager: Make copying faster with ftruncate() and a bigger buffer
Apply the same techniques from "cp" to make copying files much faster.
This commit is contained in:
parent
721585473b
commit
f76168a3ea
1 changed files with 9 additions and 2 deletions
|
@ -74,8 +74,15 @@ bool copy_file(const String& src_path, const String& dst_path, const struct stat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (src_stat.st_size > 0) {
|
||||||
|
if (ftruncate(dst_fd, src_stat.st_size) < 0) {
|
||||||
|
perror("cp: ftruncate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buffer[BUFSIZ];
|
char buffer[32768];
|
||||||
ssize_t nread = read(src_fd, buffer, sizeof(buffer));
|
ssize_t nread = read(src_fd, buffer, sizeof(buffer));
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -130,4 +137,4 @@ String get_duplicate_name(const String& path, int duplicate_count)
|
||||||
}
|
}
|
||||||
return duplicated_name.build();
|
return duplicated_name.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue