mirror of https://github.com/BOINC/boinc.git
*** empty log message ***
svn path=/trunk/boinc/; revision=5029
This commit is contained in:
parent
4031091deb
commit
98e93a0a5d
|
@ -22280,3 +22280,14 @@ David 7 Jan 2005
|
|||
|
||||
sched/
|
||||
validate_util.C
|
||||
|
||||
David 7 Jan 2005
|
||||
- moved dir hierarchy code from lib/util.C to sched/sched_util.C
|
||||
- buffer was too small by 1 byte in md5_file.C
|
||||
|
||||
lib/
|
||||
md5_file.C
|
||||
util.C,h
|
||||
sched/
|
||||
file_deleter.C
|
||||
sched_util.C,h
|
||||
|
|
|
@ -78,9 +78,8 @@ int md5_block(const unsigned char* data, int nbytes, char* output) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
std::string md5_string(const unsigned char* data, int nbytes)
|
||||
{
|
||||
char output[32];
|
||||
std::string md5_string(const unsigned char* data, int nbytes) {
|
||||
char output[MD5_LEN];
|
||||
md5_block(data, nbytes, output);
|
||||
return std::string(output);
|
||||
}
|
||||
|
|
74
lib/util.C
74
lib/util.C
|
@ -30,7 +30,6 @@
|
|||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <cerrno>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
@ -49,7 +48,6 @@
|
|||
|
||||
#include "error_numbers.h"
|
||||
#include "filesys.h"
|
||||
#include "md5_file.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef _USING_FCGI_
|
||||
|
@ -754,78 +752,6 @@ void update_average(
|
|||
avg_time = now;
|
||||
}
|
||||
|
||||
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);
|
||||
sprintf(dir, "%x", x % fanout);
|
||||
}
|
||||
|
||||
// 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,
|
||||
char* path, bool create
|
||||
) {
|
||||
char dir[256], dirpath[256];
|
||||
int retval;
|
||||
|
||||
if (fanout==0) {
|
||||
sprintf(path, "%s/%s", root, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (new_hash) {
|
||||
filename_hash(filename, fanout, dir);
|
||||
} else {
|
||||
filename_hash_old(filename, fanout, dir);
|
||||
}
|
||||
|
||||
sprintf(dirpath, "%s/%s", root, dir);
|
||||
if (create) {
|
||||
retval = boinc_mkdir(dirpath);
|
||||
if (retval && (retval != EEXIST)) {
|
||||
return ERR_MKDIR;
|
||||
}
|
||||
}
|
||||
sprintf(path, "%s/%s", dirpath, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dir_hier_url(
|
||||
const char* filename, const char* root, int fanout, bool new_hash,
|
||||
char* result
|
||||
) {
|
||||
char dir[256];
|
||||
|
||||
if (fanout==0) {
|
||||
sprintf(result, "%s/%s", root, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (new_hash) {
|
||||
filename_hash(filename, fanout, dir);
|
||||
} else {
|
||||
filename_hash_old(filename, fanout, dir);
|
||||
}
|
||||
sprintf(result, "%s/%s/%s", root, dir, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mysql_timestamp(double dt, char* p) {
|
||||
struct tm* tmp;
|
||||
time_t t = (time_t)dt;
|
||||
|
|
14
lib/util.h
14
lib/util.h
|
@ -119,20 +119,6 @@ extern int boinc_thread_cpu_time(HANDLE thread_handle, double& cpu);
|
|||
|
||||
extern void update_average(double, double, double, double&, double&);
|
||||
|
||||
// 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,
|
||||
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,
|
||||
char* result
|
||||
);
|
||||
|
||||
extern int boinc_calling_thread_cpu_time(double&);
|
||||
|
||||
// convert UNIX time to MySQL timestamp (yyyymmddhhmmss)
|
||||
|
|
|
@ -30,10 +30,11 @@
|
|||
#include "boinc_db.h"
|
||||
#include "parse.h"
|
||||
#include "util.h"
|
||||
#include "filesys.h"
|
||||
|
||||
#include "sched_config.h"
|
||||
#include "sched_util.h"
|
||||
#include "sched_msgs.h"
|
||||
#include "../lib/filesys.h"
|
||||
|
||||
#define LOCKFILE "file_deleter.out"
|
||||
#define PIDFILE "file_deleter.pid"
|
||||
|
|
|
@ -21,12 +21,15 @@ using namespace std;
|
|||
|
||||
#include <cstdlib>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "filesys.h"
|
||||
#include "md5_file.h"
|
||||
#include "error_numbers.h"
|
||||
|
||||
#include "sched_msgs.h"
|
||||
#include "sched_util.h"
|
||||
|
||||
|
@ -121,4 +124,76 @@ void get_log_path(char* p, char* filename) {
|
|||
mkdir(path, 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);
|
||||
sprintf(dir, "%x", x % fanout);
|
||||
}
|
||||
|
||||
// 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,
|
||||
char* path, bool create
|
||||
) {
|
||||
char dir[256], dirpath[256];
|
||||
int retval;
|
||||
|
||||
if (fanout==0) {
|
||||
sprintf(path, "%s/%s", root, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (new_hash) {
|
||||
filename_hash(filename, fanout, dir);
|
||||
} else {
|
||||
filename_hash_old(filename, fanout, dir);
|
||||
}
|
||||
|
||||
sprintf(dirpath, "%s/%s", root, dir);
|
||||
if (create) {
|
||||
retval = boinc_mkdir(dirpath);
|
||||
if (retval && (retval != EEXIST)) {
|
||||
return ERR_MKDIR;
|
||||
}
|
||||
}
|
||||
sprintf(path, "%s/%s", dirpath, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dir_hier_url(
|
||||
const char* filename, const char* root, int fanout, bool new_hash,
|
||||
char* result
|
||||
) {
|
||||
char dir[256];
|
||||
|
||||
if (fanout==0) {
|
||||
sprintf(result, "%s/%s", root, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (new_hash) {
|
||||
filename_hash(filename, fanout, dir);
|
||||
} else {
|
||||
filename_hash_old(filename, fanout, dir);
|
||||
}
|
||||
sprintf(result, "%s/%s/%s", root, dir, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *BOINC_RCSID_affa6ef1e4 = "$Id$";
|
||||
|
|
|
@ -36,4 +36,18 @@ extern void install_stop_signal_handler();
|
|||
extern int try_fopen(char* path, FILE*& f, char* mode);
|
||||
extern void get_log_path(char*, 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,
|
||||
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,
|
||||
char* result
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue