- Client: radically faster (on Win) version of dir_size()

(from John McLeod)

svn path=/trunk/boinc/; revision=13118
This commit is contained in:
David Anderson 2007-07-08 03:30:06 +00:00
parent e38e307d65
commit b762522c9e
2 changed files with 82 additions and 50 deletions

View File

@ -7066,19 +7066,19 @@ David 6 July 2007
server_types.C,h server_types.C,h
transitioner.C transitioner.C
Rom 7 July 2007 Rom 6 July 2007
- Additional support for VS Express Edition. - Additional support for VS Express Edition.
clientlib/win/ clientlib/win/
boinc_dll.rc boinc_dll.rc
David 7 July 2007 David 6 July 2007
- added sample host-distribution file for HR - added sample host-distribution file for HR
sched/ sched/
sample_hr_info.txt sample_hr_info.txt
David 7 July 2007 David 6 July 2007
- client: change order so that backoff because of no work - client: change order so that backoff because of no work
happens before server-requested backoff (eliminate double messages) happens before server-requested backoff (eliminate double messages)
@ -7091,8 +7091,15 @@ David 7 July 2007
hr_info.C hr_info.C
David 7 July 2007 David 6 July 2007
- bug fix to the above - bug fix to the above
client/ client/
scheduler_op.C scheduler_op.C
David 7 July 2007
- Client: radically faster (on Win) version of dir_size()
(from John McLeod)
lib/
filesys.C

View File

@ -99,17 +99,16 @@ int is_dir(const char* path) {
// //
DIRREF dir_open(const char* p) { DIRREF dir_open(const char* p) {
DIRREF dirp; DIRREF dirp;
#ifdef _WIN32
#ifdef HAVE_DIRENT_H
dirp = opendir(p);
if (!dirp) return NULL;
#elif defined(_WIN32)
if (!is_dir(p)) return NULL; if (!is_dir(p)) return NULL;
dirp = (DIR_DESC*) calloc(sizeof(DIR_DESC), 1); dirp = (DIR_DESC*) calloc(sizeof(DIR_DESC), 1);
dirp->first = true; dirp->first = true;
safe_strcpy(dirp->path, p); safe_strcpy(dirp->path, p);
strcat(dirp->path, "\\*"); strcat(dirp->path, "\\*");
dirp->handle = INVALID_HANDLE_VALUE; dirp->handle = INVALID_HANDLE_VALUE;
#else
dirp = opendir(p);
if (!dirp) return NULL;
#endif #endif
return dirp; return dirp;
} }
@ -117,19 +116,7 @@ DIRREF dir_open(const char* p) {
// Scan through a directory and return the next file name in it // Scan through a directory and return the next file name in it
// //
int dir_scan(char* p, DIRREF dirp, int p_len) { int dir_scan(char* p, DIRREF dirp, int p_len) {
#ifdef HAVE_DIRENT_H #ifdef _WIN32
while (1) {
dirent* dp = readdir(dirp);
if (dp) {
if (!strcmp(dp->d_name, ".")) continue;
if (!strcmp(dp->d_name, "..")) continue;
if (p) strlcpy(p, dp->d_name, p_len);
return 0;
} else {
return ERR_READDIR;
}
}
#elif defined(_WIN32)
WIN32_FIND_DATA data; WIN32_FIND_DATA data;
while (1) { while (1) {
if (dirp->first) { if (dirp->first) {
@ -158,55 +145,54 @@ int dir_scan(char* p, DIRREF dirp, int p_len) {
} }
} }
} }
#else
while (1) {
dirent* dp = readdir(dirp);
if (dp) {
if (!strcmp(dp->d_name, ".")) continue;
if (!strcmp(dp->d_name, "..")) continue;
if (p) strlcpy(p, dp->d_name, p_len);
return 0;
} else {
return ERR_READDIR;
}
}
#endif #endif
} }
// Close a directory // Close a directory
// //
void dir_close(DIRREF dirp) { void dir_close(DIRREF dirp) {
#ifdef HAVE_DIRENT_H #ifdef _WIN32
if (dirp) {
closedir(dirp);
}
#elif defined(_WIN32)
if (dirp->handle != INVALID_HANDLE_VALUE) { if (dirp->handle != INVALID_HANDLE_VALUE) {
FindClose(dirp->handle); FindClose(dirp->handle);
dirp->handle = INVALID_HANDLE_VALUE; dirp->handle = INVALID_HANDLE_VALUE;
} }
free(dirp); free(dirp);
#else
if (dirp) {
closedir(dirp);
}
#endif #endif
} }
DirScanner::DirScanner(string const& path) { DirScanner::DirScanner(string const& path) {
#ifdef HAVE_DIRENT_H #ifdef _WIN32
dirp = opendir(path.c_str());
#elif defined(_WIN32)
first = true; first = true;
handle = INVALID_HANDLE_VALUE; handle = INVALID_HANDLE_VALUE;
if (!is_dir((char*)path.c_str())) { if (!is_dir((char*)path.c_str())) {
return; return;
} }
dir = path + "\\*"; dir = path + "\\*";
#else
dirp = opendir(path.c_str());
#endif #endif
} }
// Scan through a directory and return the next file name in it // Scan through a directory and return the next file name in it
// //
bool DirScanner::scan(string& s) { bool DirScanner::scan(string& s) {
#ifdef HAVE_DIRENT_H #ifdef _WIN32
if (!dirp) return false;
while (1) {
dirent* dp = readdir(dirp);
if (dp) {
if (dp->d_name[0] == '.') continue;
s = dp->d_name;
return true;
} else {
return false;
}
}
#elif defined(_WIN32)
WIN32_FIND_DATA data; WIN32_FIND_DATA data;
while (1) { while (1) {
if (first) { if (first) {
@ -231,19 +217,31 @@ bool DirScanner::scan(string& s) {
} }
} }
} }
#else
if (!dirp) return false;
while (1) {
dirent* dp = readdir(dirp);
if (dp) {
if (dp->d_name[0] == '.') continue;
s = dp->d_name;
return true;
} else {
return false;
}
}
#endif #endif
} }
// Close a directory
DirScanner::~DirScanner() { DirScanner::~DirScanner() {
#ifdef HAVE_DIRENT_H #ifdef _WIN32
if (dirp) {
closedir(dirp);
}
#elif defined(_WIN32)
if (handle != INVALID_HANDLE_VALUE) { if (handle != INVALID_HANDLE_VALUE) {
FindClose(handle); FindClose(handle);
} }
#else
if (dirp) {
closedir(dirp);
}
#endif #endif
} }
@ -354,8 +352,34 @@ int clean_out_dir(const char* dirpath) {
} }
// return total size of files in directory and its subdirectories // return total size of files in directory and its subdirectories
// Special version for Win because stat() is slow, can be avoided
// //
int dir_size(const char* dirpath, double& size, bool recurse) { int dir_size(const char* dirpath, double& size, bool recurse) {
#ifdef WIN32
size = 0.0;
WIN32_FIND_DATA findData;
HANDLE hFind = ::FindFirstFile(dirpath, &findData);
if (INVALID_HANDLE_VALUE != hFind) {
do {
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (!recurse) continue;
if (!strcmp(findData.cFileName, ".")) continue;
if (!strcmp(findData.cFileName, "..")) continue;
double dsize = 0;
char buf[_MAX_PATH];
::sprintf(buf, "%s\\%s", dirpath, findData.cFileName);
dir_size(buf, dsize, recurse);
size += dsize;
} else {
size += findData.nFileSizeLow + (__int64(findData.nFileSizeHigh) << 32);
}
} while (FindNextFile(hFind, &findData));
::FindClose(hFind);
} else {
return ERR_OPENDIR;
}
#else
char filename[256], subdir[256]; char filename[256], subdir[256];
int retval=0; int retval=0;
DIRREF dirp; DIRREF dirp;
@ -383,6 +407,7 @@ int dir_size(const char* dirpath, double& size, bool recurse) {
} }
dir_close(dirp); dir_close(dirp);
return 0; return 0;
#endif
} }
FILE* boinc_fopen(const char* path, const char* mode) { FILE* boinc_fopen(const char* path, const char* mode) {