Jeff - pull out old hier dir/url hash function

svn path=/trunk/boinc/; revision=8163
This commit is contained in:
Jeff Cobb 2005-09-23 21:09:00 +00:00
parent 428e6c9a7f
commit 5218ad9bdf
11 changed files with 19 additions and 53 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -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);

View File

@ -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(

View File

@ -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;
}

View File

@ -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
);

View File

@ -47,10 +47,7 @@ int get_output_file_path(RESULT const& result, string& path_str) {
if (!parse_str(result.xml_doc_out, "<name>", 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;
}

View File

@ -46,7 +46,7 @@ int get_file_path(WORKUNIT& wu, char* path) {
bool flag;
flag = parse_str(wu.xml_doc, "<name>", 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;
}

View File

@ -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,
" <name>%s</name>\n"
@ -418,7 +416,7 @@ int check_files(char** infiles, int ninfiles, SCHED_CONFIG& config) {
for (i=0; i<ninfiles; i++) {
dir_hier_path(
infiles[i], config.download_dir, config.uldl_dir_fanout, true, path
infiles[i], config.download_dir, config.uldl_dir_fanout, path
);
if (!boinc_file_exists(path)) {
return 1;

View File

@ -46,7 +46,7 @@ int main(int argc, char** argv) {
DirScanner scanner(src_dir);
while (scanner.scan(filename)) {
retval = dir_hier_path(filename.c_str(), dst_dir, fanout, true, dst_path, true);
retval = dir_hier_path(filename.c_str(), dst_dir, fanout, dst_path, true);
if (retval) {
fprintf(stderr, "dir_hier_path: %d\n", retval);
exit(1);

View File

@ -39,7 +39,7 @@ int main(int /*argc*/, char** argv) {
exit(1);
}
dir_hier_path(argv[1], "", config.uldl_dir_fanout, true, path);
dir_hier_path(argv[1], "", config.uldl_dir_fanout, path);
printf("%s%s\n", config.download_dir, path);
}