From 5ce5d79c0fc65c850af27b2aa9d540d65d2e1a25 Mon Sep 17 00:00:00 2001 From: Bruce Allen Date: Fri, 31 Dec 2004 15:39:05 +0000 Subject: [PATCH] Some improvements on the md5-info caching. If the 'data' file is more recent than the 'md5info', then ignore md5info. If md5info has *exactly* the right format (no extra or missing characters) then remove it in this case (only). Don't write an md5info file if another file is found with the same name. Thus if someone has two data files called X and X.md5, unless X.md5 has the exact correct syntax for an md5-info cache file, it won't be removed or used. Still disabled by default. Use -DBOINC_CACHE_MD5 to enable it. svn path=/trunk/boinc/; revision=4973 --- checkin_notes | 27 ++++++++++ tools/backend_lib.C | 117 +++++++++++++++++++++++++++++++++----------- 2 files changed, 116 insertions(+), 28 deletions(-) diff --git a/checkin_notes b/checkin_notes index 20b7ed9d5e..e6bec394a9 100755 --- a/checkin_notes +++ b/checkin_notes @@ -22011,3 +22011,30 @@ Bruce 30 Dec 2004 tools/ backend_lib.C + +Bruce 31 Dec 2004 + + - Some improvements on the md5-info caching. If the 'data' file is + more recent than the 'md5info', then ignore md5info. If md5info + has *exactly* the right format (no extra or missing characters) then + remove it in this case (only). Don't write an md5info file if + another file is found with the same name. Thus if someone has two + data files called X and X.md5, unless X.md5 has the exact correct + syntax for an md5-info cache file, it won't be removed or used. + Still disabled by default. Use -DBOINC_CACHE_MD5 to enable it. + + - Improvements to ops/ pages, from Christian Beer. Show all fields of + WU. Display status summaries based on mod-times. + + - Make 'grep logs' function assume default of *.log for filenames, unless + specified. + + tools/ + backend_lib.C + html/ + inc/ + db_ops.inc + util.inc + ops/ + show_log.php + diff --git a/tools/backend_lib.C b/tools/backend_lib.C index 053879c4e5..3567ae9550 100644 --- a/tools/backend_lib.C +++ b/tools/backend_lib.C @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "boinc_db.h" #include "crypt.h" @@ -59,6 +61,88 @@ int read_filename(const char* path, char* buf, int len) { return retval; } +#ifdef BOINC_CACHE_MD5 +static bool got_md5_info( + const char *path, + char *md5data, + double *nbytes +) { + + // look for file named FILENAME.md5 containing md5sum and length. + // If found, and newer mod time than file, read md5 sum and file + // length from it. + + FILE *fp; + char md5name[512]; + struct stat md5stat, filestat; + bool retval=false; + char endline='\0'; + + sprintf(md5name, "%s.md5", path); + + // get mod times for file + if (stat(path, &filestat)) + return retval; + + // get mod time for md5 cache file + if (stat(md5name, &md5stat)) + return retval; + + // if cached md5 newer, then open it + if (!(fp=fopen(md5name, "r"))) + return retval; + + // read two quantities: md5 sum and length. If we can't read + // these, or there is MORE stuff in the file' it's not an md5 + // cache file + if (3 == fscanf(fp, "%s %lf%c", md5data, nbytes, &endline) && + endline=='\n' && + EOF==fgetc(fp) + ) + retval=true; + fclose(fp); + + // if this is one of our cached md5 files, but it's OLDER than the + // data file which it supposedly corresponds to, delete it. + if (retval && md5stat.st_mtime