Fixes to BOINC zip library from Carl Christensen. Carl says:

"I found a problem with boinc_zip; it seems some Linux STL's
aren't very nice about classes that are inherited from their
objects on multiple use; or huge file lists that we use on CPDN.
So I rewrite it to just use "straight" std::string's in a vector.
It's fully backwardly compatible and seems to work fine."

svn path=/trunk/boinc/; revision=9203
This commit is contained in:
Bruce Allen 2006-01-09 22:06:19 +00:00
parent 18db739b31
commit 998db46c9b
3 changed files with 216 additions and 229 deletions

View File

@ -240,3 +240,15 @@ Rom 9 Jan 2006 (HEAD)
- Tag for 5.3.9 release, all platforms
boinc_core_release_5_3_9
Bruce 9 Jan 2006
- Fixes to BOINC zip library from Carl Christensen. Carl says:
"I found a problem with boinc_zip; it seems some Linux STL's
aren't very nice about classes that are inherited from their
objects on multiple use; or huge file lists that we use on CPDN.
So I rewrite it to just use "straight" std::string's in a vector.
It's fully backwardly compatible and seems to work fine."
zip/
boinc_zip.h
boinc_zip.cpp

View File

@ -33,53 +33,43 @@ using std::string;
#define _MAX_PATH 255
#endif
// ZipFileEntry/List stuff
ZipFileEntry::ZipFileEntry(const std::string strIn, unsigned char ucSort)
{
this->assign(strIn);
stat(strIn.c_str(), &m_statFile);
m_ucSort = ucSort;
}
unsigned char g_ucSort;
ZipFileEntry::ZipFileEntry(const std::string strIn, const struct stat instat, unsigned char ucSort)
{
this->assign(strIn);
m_statFile = instat;
m_ucSort = ucSort;
}
// a "binary predicate" for use by the std::sort algorithm
// return true if "first > second" according to the g_ucSort type
ZipFileEntry::~ZipFileEntry()
{
this->assign("");
}
bool StringVectorSort(const std::string& first, const std::string& second)
{
bool ZipFileEntry::operator< (const ZipFileEntry& other) const
{
bool bRet = false;
if (m_ucSort & SORT_NAME
&& m_ucSort & SORT_ASCENDING
&& strcmp(this->c_str(), other.c_str())<0)
if (g_ucSort & SORT_NAME
&& g_ucSort & SORT_ASCENDING
&& strcmp(first.c_str(), second.c_str())<0)
bRet = true;
else if (m_ucSort & SORT_NAME
&& m_ucSort & SORT_DESCENDING
&& strcmp(this->c_str(), other.c_str())>0)
bRet = true;
else if (m_ucSort & SORT_TIME
&& m_ucSort & SORT_ASCENDING
&& this->m_statFile.st_mtime < other.m_statFile.st_mtime)
bRet = true;
else if (m_ucSort & SORT_TIME
&& m_ucSort & SORT_DESCENDING
&& this->m_statFile.st_mtime > other.m_statFile.st_mtime)
else if (g_ucSort & SORT_NAME
&& g_ucSort & SORT_DESCENDING
&& strcmp(first.c_str(), second.c_str())>0)
bRet = true;
else if (g_ucSort & SORT_TIME)
{
struct stat st[2];
stat(first.c_str(), &st[0]);
stat(second.c_str(), &st[1]);
if (g_ucSort & SORT_ASCENDING) {
bRet = st[0].st_mtime < st[1].st_mtime;
}
else {
bRet = st[0].st_mtime > st[1].st_mtime;
}
}
return bRet;
}
}
int boinc_zip(int bZipType, const std::string szFileZip, const std::string szFileIn)
{
ZipFileList tempvec;
tempvec.push_back(ZipFileEntry(szFileIn));
tempvec.push_back(szFileIn);
return boinc_zip(bZipType, szFileZip, &tempvec);
}
@ -89,7 +79,7 @@ int boinc_zip(int bZipType, const char* szFileZip, const char* szFileIn)
strFileZip.assign(szFileZip);
strFileIn.assign(szFileIn);
ZipFileList tempvec;
tempvec.push_back(ZipFileEntry(strFileIn));
tempvec.push_back(strFileIn);
return boinc_zip(bZipType, strFileZip, &tempvec);
}
@ -194,6 +184,7 @@ bool boinc_filelist(const std::string directory,
ZipFileList* pList,
const unsigned char ucSort, const bool bClear)
{
g_ucSort = ucSort; // set the global sort type right off the bat
std::string strFile;
// at most three |'s may be passed in pattern match
int iPos[3], iFnd, iCtr, i, lastPos;
@ -300,17 +291,18 @@ bool boinc_filelist(const std::string directory,
strFullPath = strUserDir + strFile;
// only add if the file really exists (i.e. not a directory)
if (is_file(strFullPath.c_str())) {
ZipFileEntry zfe(strFullPath, ucSort);
pList->push_back(zfe);
pList->push_back(strFullPath);
}
}
}
// sort by file creation time
std::sort(pList->begin(), pList->end()); // may as well sort it?
if (pList->size()>1) { // sort if list is greather than 1
std::sort(pList->begin(), pList->end(), StringVectorSort); // may as well sort it?
}
return true;
}
const char *BOINC_RCSID_bdf38b2dfb = "$Id$";

View File

@ -32,21 +32,7 @@
#ifdef __cplusplus
using std::string;
class ZipFileEntry :public std::string
{
public:
ZipFileEntry(const std::string strIn, unsigned char ucSort = SORT_NAME | SORT_DESCENDING);
ZipFileEntry(const std::string strIn, const struct stat instat, unsigned char ucSort = SORT_NAME | SORT_DESCENDING);
~ZipFileEntry();
bool operator< (const ZipFileEntry& other) const; // sorts by filetime
struct stat m_statFile; // keep file stats in here
private:
unsigned char m_ucSort;
};
typedef std::vector<ZipFileEntry> ZipFileList;
typedef std::vector<std::string> ZipFileList;
// forward declarations for boinc_zip functions
// note it's basically like running zip/unzip, just comprise an argc/argv
@ -77,6 +63,3 @@ extern
#endif
int boinc_zip(int bZipType, const char* szFileZip, const char* szFileIn);