From be1960650183348b679f76ba53e60659ba0e36f4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 2 Nov 2019 23:47:22 +0100 Subject: [PATCH] cp: Fail immediately if there's not enough space for the destination Instead of writing until we run out of space, just fail immediately. --- Userland/cp.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/cp.cpp b/Userland/cp.cpp index 93e1db6cd3..971c1453a6 100644 --- a/Userland/cp.cpp +++ b/Userland/cp.cpp @@ -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 (;;) {