summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-02 23:47:22 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-02 23:47:22 +0100
commitbe1960650183348b679f76ba53e60659ba0e36f4 (patch)
treecc28750daefb1dec57875863a58441c307eef8e6 /Userland
parentd9bef3e237833696988c57daeb402d79a6d7dee0 (diff)
downloadserenity-be1960650183348b679f76ba53e60659ba0e36f4.zip
cp: Fail immediately if there's not enough space for the destination
Instead of writing until we run out of space, just fail immediately.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/cp.cpp6
1 files 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 (;;) {