From ce9666f29cea2cede9f6b0ed1c904e6986919f5e Mon Sep 17 00:00:00 2001 From: Karl Chen Date: Fri, 1 Aug 2003 21:20:20 +0000 Subject: [PATCH] don't download if md5 & sig match already svn path=/trunk/boinc/; revision=1942 --- client/client_state.h | 18 +++++++++--------- client/cs_files.C | 9 ++++++--- client/pers_file_xfer.C | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/client/client_state.h b/client/client_state.h index e9bfe185e6..6fdff3c3e4 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -2,18 +2,18 @@ // Version 1.0 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://boinc.berkeley.edu/license_1.0.txt -// +// // Software distributed under the License is distributed on an "AS IS" // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the // License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is the Berkeley Open Infrastructure for Network Computing. -// +// under the License. +// +// The Original Code is the Berkeley Open Infrastructure for Network Computing. +// // The Initial Developer of the Original Code is the SETI@home project. // Portions created by the SETI@home project are Copyright (C) 2002 -// University of California at Berkeley. All Rights Reserved. -// +// University of California at Berkeley. All Rights Reserved. +// // Contributor(s): // @@ -147,7 +147,7 @@ private: // if set, run benchmarks on client startup bool activities_suspended; bool previous_activities_suspended; - // if activities were suspended in the previous check_suspend(); + // if activities were suspended in the previous check_suspend(); // this is needed to update GUI windows after suspension and close transfers/files. int exit_after_app_start_secs; // if nonzero, exit this many seconds after starting an app @@ -165,7 +165,7 @@ private: int link_workunit(PROJECT*, WORKUNIT*); int link_result(PROJECT*, RESULT*); int latest_version_num(char*); - int check_suspend_activities(int&); + void check_suspend_activities(int&); int suspend_activities(int reason); int resume_activities(); int make_project_dirs(); diff --git a/client/cs_files.C b/client/cs_files.C index 6fb26c4e25..6c3d9412f4 100644 --- a/client/cs_files.C +++ b/client/cs_files.C @@ -95,17 +95,20 @@ int verify_downloaded_file(char* pathname, FILE_INFO& file_info) { pathname, file_info.file_signature, project->code_sign_key, verified ); if (retval) { - msg_printf(project, MSG_ERROR, "verify_downloaded_file(): internal error\n"); + msg_printf(project, MSG_ERROR, "verify_downloaded_file(): %s: internal error\n", + pathname); return ERR_RSA_FAILED; } if (!verified) { - msg_printf(project, MSG_ERROR, "verify_downloaded_file(): file not verified\n"); + msg_printf(project, MSG_ERROR, "verify_downloaded_file(): %s: file not verified\n", + pathname); return ERR_RSA_FAILED; } } else if (strlen(file_info.md5_cksum)) { retval = md5_file(pathname, cksum, file_info.nbytes); if (strcmp(cksum, file_info.md5_cksum) || retval) { - msg_printf(project, MSG_ERROR, "verify_downloaded_file(): MD5 check failed\n"); + msg_printf(project, MSG_ERROR, "verify_downloaded_file(): %s: MD5 check failed\n", + pathname); return ERR_MD5_FAILED; } } diff --git a/client/pers_file_xfer.C b/client/pers_file_xfer.C index 7b3be05a75..b473e347f1 100644 --- a/client/pers_file_xfer.C +++ b/client/pers_file_xfer.C @@ -30,6 +30,7 @@ #include "parse.h" #include "util.h" #include "log_flags.h" +#include "filesys.h" // PERS_FILE_XFER represents a persistent file transfer. // A set of URLs is given. @@ -80,6 +81,31 @@ int PERS_FILE_XFER::start_xfer() { return ERR_IDLE_PERIOD; } + // Does the file exist already? this could happen for example if we are + // downloading an application which exists from a previous installation, + // or if we get the same input file (which is unlikely outside the beta + // test microcosm) + if (!is_upload) { + char pathname[256]; + get_pathname(fip, pathname); + double existing_size = 0; + if (!file_size(pathname, existing_size) && existing_size == fip->nbytes) { + // file exists already and has the right size + retval = verify_downloaded_file(pathname, *fip); + if (!retval) { + // signature and checksum match + retval = fip->set_permissions(); + fip->status = FILE_PRESENT; + xfer_done = true; + + msg_printf( + fip->project, MSG_INFO, "File %s exists already, skipping download", pathname); + + return retval; + } + } + } + // Create a new FILE_XFER object and initialize a // download or upload for the persistent file transfer //