cp: Fail immediately if there's not enough space for the destination

Instead of writing until we run out of space, just fail immediately.
This commit is contained in:
Andreas Kling 2019-11-02 23:47:22 +01:00
parent d9bef3e237
commit be19606501
Notes: sideshowbarker 2024-07-19 11:28:01 +09:00

View file

@ -90,8 +90,10 @@ 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);
if (ftruncate(dst_fd, src_stat.st_size) < 0) {
perror("cp: ftruncate");
return false;
}
}
for (;;) {