From be50103751667952b11793ffbadc354232e0b01d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 2 Feb 2016 11:51:45 -0800 Subject: [PATCH] file upoad handler: if file is already there, don't upload again Notes: 1) We still need to read all the data from socket (copy_socket_to_null()); otherwise the client will block on the send, and never get the success reply. The previous approach (read-only file) didn't do this. All we're saving is disk I/O on server. 2) The client reports a result only after it know that all its output files have successfully been uploaded. It won't re-upload anything if that's the case. --- sched/file_upload_handler.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sched/file_upload_handler.cpp b/sched/file_upload_handler.cpp index 874cbac995..0f64c6ecaa 100644 --- a/sched/file_upload_handler.cpp +++ b/sched/file_upload_handler.cpp @@ -289,7 +289,7 @@ int handle_file_upload(FILE* in, R_RSA_PUBLIC_KEY& key) { double max_nbytes=-1; char xml_signature[1024]; int retval; - double offset=0, nbytes = -1; + double offset=0, nbytes = -1, size; bool is_valid, btemp; strcpy(name, ""); @@ -402,6 +402,17 @@ int handle_file_upload(FILE* in, R_RSA_PUBLIC_KEY& key) { name, boincerror(retval) ); } + + // if file already exists and is full size, don't upload again. + // + if (!file_size(path, size) && (size == nbytes)) { + log_messages.printf(MSG_NORMAL, + "file %s exists and is right size - skipping\n", name + ); + copy_socket_to_null(in); + return return_success(0); + } + log_messages.printf(MSG_NORMAL, "Starting upload of %s from %s [offset=%.0f, nbytes=%.0f]\n", name,