Subject: bug#18316: [PATCH] warn on too large file copies

From: Adam <[email-masked]>
Date: Fri, 22 Aug 2014 16:56:13 +0100

When files are being copied, they can hit the following loop:

  while (max_n_read)
    { 
      ...
      // return true if file finishes copying
      // return false if error occurs     
      // copy some file
      // deduct bytes copied from max_n_read
      ...
    }

  return true;

If max_n_read reaches 0, the copy does not return a warning or a failure
but instead returns that the copy completed successfully.

I believe when copying files as large as these, if the maximum transfer
were to be reached then the copy should not return false (as this will
delete the failed destination file), but instead produce a warning and
return true. 

I have attached a patch against the git master. Please review and
consider it's inclusion.

I apologise if there is an issue with this report as it is my first time
submitting a patch to coreutils. 

Thanks,
Adam Shore
Submitted by: Adam Shore <[email-masked]>
Date: 2014-08-22
Inital Package Version: 8.23
Description: Adds warning when copying files too large

diff --git a/src/copy.c b/src/copy.c
index 26d5bdd..64e1d61 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -226,6 +226,10 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
       *last_write_made_hole = make_hole;
     }
 
+  if (!max_n_read)
+    error (0, 0, _("warning: could not copy all of %s, file too large"),
+           quote (src_name));
+
   return true;
 }