diff --git a/Userland/cp.cpp b/Userland/cp.cpp index 1a4a5d554e..d2e12e0153 100644 --- a/Userland/cp.cpp +++ b/Userland/cp.cpp @@ -89,6 +89,11 @@ bool copy_file(String src_path, String dst_path, struct stat src_stat, int src_f } } + if (src_stat.st_size > 0) { + // NOTE: This is primarily an optimization, so it's not the end if it fails. + ftruncate(dst_fd, src_stat.st_size); + } + for (;;) { char buffer[BUFSIZ]; ssize_t nread = read(src_fd, buffer, sizeof(buffer)); @@ -151,4 +156,4 @@ bool copy_directory(String src_path, String dst_path) } } return true; -} \ No newline at end of file +}