From 5218ad9bdf0f5b8a7337ec5886a72034b52707ab Mon Sep 17 00:00:00 2001 From: Jeff Cobb Date: Fri, 23 Sep 2005 21:09:00 +0000 Subject: [PATCH] Jeff - pull out old hier dir/url hash function svn path=/trunk/boinc/; revision=8163 --- sched/file_deleter.C | 9 +-------- sched/file_upload_handler.C | 4 ++-- sched/make_work.C | 4 ++-- sched/sched_locality.C | 2 +- sched/sched_util.C | 30 ++++-------------------------- sched/sched_util.h | 4 ++-- sched/validate_util.C | 5 +---- sched/wu_check.C | 2 +- tools/backend_lib.C | 8 +++----- tools/dir_hier_move.C | 2 +- tools/dir_hier_path.C | 2 +- 11 files changed, 19 insertions(+), 53 deletions(-) diff --git a/sched/file_deleter.C b/sched/file_deleter.C index 8a49a620ae..22e22e7e2f 100644 --- a/sched/file_deleter.C +++ b/sched/file_deleter.C @@ -61,14 +61,7 @@ int id_modulus=0, id_remainder=0; // int get_file_path(char *filename, char* upload_dir, int fanout, char* path) { - dir_hier_path(filename, upload_dir, fanout, true, path); - if (boinc_file_exists(path)) { - return 0; - } - - // TODO: get rid of the old hash in about 3/2005 - // - dir_hier_path(filename, upload_dir, fanout, false, path); + dir_hier_path(filename, upload_dir, fanout, path); if (boinc_file_exists(path)) { return 0; } diff --git a/sched/file_upload_handler.C b/sched/file_upload_handler.C index 8b14e767d3..c443083751 100644 --- a/sched/file_upload_handler.C +++ b/sched/file_upload_handler.C @@ -304,7 +304,7 @@ int handle_file_upload(FILE* in, R_RSA_PUBLIC_KEY& key) { } retval = dir_hier_path( - file_info.name, config.upload_dir, config.uldl_dir_fanout, true, + file_info.name, config.upload_dir, config.uldl_dir_fanout, path, true ); log_messages.printf( @@ -351,7 +351,7 @@ int handle_get_file_size(char* file_name) { // TODO: check to ensure path doesn't point somewhere bad // Use 64-bit variant // - dir_hier_path(file_name, config.upload_dir, config.uldl_dir_fanout, true, path); + dir_hier_path(file_name, config.upload_dir, config.uldl_dir_fanout, path); fd=open(path, O_WRONLY|O_APPEND); if (fd<0 && ENOENT==errno) { diff --git a/sched/make_work.C b/sched/make_work.C index 5a98d2a75c..0a9faedc2f 100644 --- a/sched/make_work.C +++ b/sched/make_work.C @@ -137,11 +137,11 @@ void make_new_wu( new_file_name, "%s__%d_%d", file_name, start_time, seqno++ ); dir_hier_path( - file_name, config.download_dir, config.uldl_dir_fanout, true, + file_name, config.download_dir, config.uldl_dir_fanout, pathname ); dir_hier_path( - new_file_name, config.download_dir, config.uldl_dir_fanout, true, + new_file_name, config.download_dir, config.uldl_dir_fanout, new_pathname, true ); retval = link(pathname, new_pathname); diff --git a/sched/sched_locality.C b/sched/sched_locality.C index 9190ace74e..485628d321 100644 --- a/sched/sched_locality.C +++ b/sched/sched_locality.C @@ -221,7 +221,7 @@ int decrement_disk_space_locality( // Get path to file, and determine its size dir_hier_path( - filename, config.download_dir, config.uldl_dir_fanout, true, path, false + filename, config.download_dir, config.uldl_dir_fanout, path, false ); if (stat(path, &buf)) { log_messages.printf( diff --git a/sched/sched_util.C b/sched/sched_util.C index 7dfd70f232..3a745fc2be 100644 --- a/sched/sched_util.C +++ b/sched/sched_util.C @@ -127,15 +127,6 @@ void get_log_path(char* p, const char* filename) { mkdir(dir, 0777); } -static void filename_hash_old(const char* filename, int fanout, char* dir) { - int sum=0; - const char* p = filename; - - while (*p) sum += *p++; - sum %= fanout; - sprintf(dir, "%x", sum); -} - static void filename_hash(const char* filename, int fanout, char* dir) { std::string s = md5_string((const unsigned char*)filename, strlen(filename)); int x = strtol(s.substr(1, 7).c_str(), 0, 16); @@ -144,14 +135,9 @@ static void filename_hash(const char* filename, int fanout, char* dir) { // given a filename, compute its path in a directory hierarchy // If create is true, create the directory if needed -// NOTE: this first time around I used a bad hash function. -// During the period of transition to the good hash function, -// programs to look for files (validator, assimilator, file deleter) -// will have to try both the old and new variants. -// We can phase this out after everyone is caught up. // int dir_hier_path( - const char* filename, const char* root, int fanout, bool new_hash, + const char* filename, const char* root, int fanout, char* path, bool create ) { char dir[256], dirpath[256]; @@ -162,11 +148,7 @@ int dir_hier_path( return 0; } - if (new_hash) { - filename_hash(filename, fanout, dir); - } else { - filename_hash_old(filename, fanout, dir); - } + filename_hash(filename, fanout, dir); sprintf(dirpath, "%s/%s", root, dir); if (create) { @@ -180,7 +162,7 @@ int dir_hier_path( } int dir_hier_url( - const char* filename, const char* root, int fanout, bool new_hash, + const char* filename, const char* root, int fanout, char* result ) { char dir[256]; @@ -190,11 +172,7 @@ int dir_hier_url( return 0; } - if (new_hash) { - filename_hash(filename, fanout, dir); - } else { - filename_hash_old(filename, fanout, dir); - } + filename_hash(filename, fanout, dir); sprintf(result, "%s/%s/%s", root, dir, filename); return 0; } diff --git a/sched/sched_util.h b/sched/sched_util.h index f480527400..270cc1b2fd 100644 --- a/sched/sched_util.h +++ b/sched/sched_util.h @@ -41,14 +41,14 @@ extern void get_log_path(char*, const char*); // convert filename to path in a hierarchical directory system // extern int dir_hier_path( - const char* filename, const char* root, int fanout, bool new_hash, + const char* filename, const char* root, int fanout, char* result, bool create=false ); // convert filename to URL in a hierarchical directory system // extern int dir_hier_url( - const char* filename, const char* root, int fanout, bool new_hash, + const char* filename, const char* root, int fanout, char* result ); diff --git a/sched/validate_util.C b/sched/validate_util.C index b4eaa5b46c..e883b94069 100644 --- a/sched/validate_util.C +++ b/sched/validate_util.C @@ -47,10 +47,7 @@ int get_output_file_path(RESULT const& result, string& path_str) { if (!parse_str(result.xml_doc_out, "", buf, sizeof(buf))) { return ERR_XML_PARSE; } - dir_hier_path(buf, config.upload_dir, config.uldl_dir_fanout, true, path); - if (!boinc_file_exists(path)) { - dir_hier_path(buf, config.upload_dir, config.uldl_dir_fanout, false, path); - } + dir_hier_path(buf, config.upload_dir, config.uldl_dir_fanout, path); path_str = path; return 0; } diff --git a/sched/wu_check.C b/sched/wu_check.C index d65f5f5a18..74af523089 100644 --- a/sched/wu_check.C +++ b/sched/wu_check.C @@ -46,7 +46,7 @@ int get_file_path(WORKUNIT& wu, char* path) { bool flag; flag = parse_str(wu.xml_doc, "", buf, sizeof(buf)); if (!flag) return ERR_XML_PARSE; - dir_hier_path(buf, config.download_dir, config.uldl_dir_fanout, true, path); + dir_hier_path(buf, config.download_dir, config.uldl_dir_fanout, path); return 0; } diff --git a/tools/backend_lib.C b/tools/backend_lib.C index 0e303bef48..4d4adee3a9 100644 --- a/tools/backend_lib.C +++ b/tools/backend_lib.C @@ -185,8 +185,7 @@ static int process_wu_template( } dir_hier_path( infiles[file_number], config.download_dir, - config.uldl_dir_fanout, true, - path, true + config.uldl_dir_fanout, path, true ); // if file isn't found in hierarchy, @@ -214,8 +213,7 @@ static int process_wu_template( dir_hier_url( infiles[file_number], config.download_url, - config.uldl_dir_fanout, true, - url + config.uldl_dir_fanout, url ); sprintf(buf, " %s\n" @@ -418,7 +416,7 @@ int check_files(char** infiles, int ninfiles, SCHED_CONFIG& config) { for (i=0; i