mirror of https://github.com/BOINC/boinc.git
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:
parent
18db739b31
commit
998db46c9b
|
@ -240,3 +240,15 @@ Rom 9 Jan 2006 (HEAD)
|
||||||
- Tag for 5.3.9 release, all platforms
|
- Tag for 5.3.9 release, all platforms
|
||||||
boinc_core_release_5_3_9
|
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
|
||||||
|
|
||||||
|
|
|
@ -33,53 +33,43 @@ using std::string;
|
||||||
#define _MAX_PATH 255
|
#define _MAX_PATH 255
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ZipFileEntry/List stuff
|
unsigned char g_ucSort;
|
||||||
ZipFileEntry::ZipFileEntry(const std::string strIn, unsigned char ucSort)
|
|
||||||
{
|
|
||||||
this->assign(strIn);
|
|
||||||
stat(strIn.c_str(), &m_statFile);
|
|
||||||
m_ucSort = ucSort;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZipFileEntry::ZipFileEntry(const std::string strIn, const struct stat instat, unsigned char ucSort)
|
// a "binary predicate" for use by the std::sort algorithm
|
||||||
{
|
// return true if "first > second" according to the g_ucSort type
|
||||||
this->assign(strIn);
|
|
||||||
m_statFile = instat;
|
|
||||||
m_ucSort = ucSort;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZipFileEntry::~ZipFileEntry()
|
bool StringVectorSort(const std::string& first, const std::string& second)
|
||||||
{
|
{
|
||||||
this->assign("");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ZipFileEntry::operator< (const ZipFileEntry& other) const
|
|
||||||
{
|
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
if (m_ucSort & SORT_NAME
|
if (g_ucSort & SORT_NAME
|
||||||
&& m_ucSort & SORT_ASCENDING
|
&& g_ucSort & SORT_ASCENDING
|
||||||
&& strcmp(this->c_str(), other.c_str())<0)
|
&& strcmp(first.c_str(), second.c_str())<0)
|
||||||
bRet = true;
|
bRet = true;
|
||||||
else if (m_ucSort & SORT_NAME
|
else if (g_ucSort & SORT_NAME
|
||||||
&& m_ucSort & SORT_DESCENDING
|
&& g_ucSort & SORT_DESCENDING
|
||||||
&& strcmp(this->c_str(), other.c_str())>0)
|
&& strcmp(first.c_str(), second.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)
|
|
||||||
bRet = true;
|
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;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int boinc_zip(int bZipType, const std::string szFileZip, const std::string szFileIn)
|
int boinc_zip(int bZipType, const std::string szFileZip, const std::string szFileIn)
|
||||||
{
|
{
|
||||||
ZipFileList tempvec;
|
ZipFileList tempvec;
|
||||||
tempvec.push_back(ZipFileEntry(szFileIn));
|
tempvec.push_back(szFileIn);
|
||||||
return boinc_zip(bZipType, szFileZip, &tempvec);
|
return boinc_zip(bZipType, szFileZip, &tempvec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +79,7 @@ int boinc_zip(int bZipType, const char* szFileZip, const char* szFileIn)
|
||||||
strFileZip.assign(szFileZip);
|
strFileZip.assign(szFileZip);
|
||||||
strFileIn.assign(szFileIn);
|
strFileIn.assign(szFileIn);
|
||||||
ZipFileList tempvec;
|
ZipFileList tempvec;
|
||||||
tempvec.push_back(ZipFileEntry(strFileIn));
|
tempvec.push_back(strFileIn);
|
||||||
return boinc_zip(bZipType, strFileZip, &tempvec);
|
return boinc_zip(bZipType, strFileZip, &tempvec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +184,7 @@ bool boinc_filelist(const std::string directory,
|
||||||
ZipFileList* pList,
|
ZipFileList* pList,
|
||||||
const unsigned char ucSort, const bool bClear)
|
const unsigned char ucSort, const bool bClear)
|
||||||
{
|
{
|
||||||
|
g_ucSort = ucSort; // set the global sort type right off the bat
|
||||||
std::string strFile;
|
std::string strFile;
|
||||||
// at most three |'s may be passed in pattern match
|
// at most three |'s may be passed in pattern match
|
||||||
int iPos[3], iFnd, iCtr, i, lastPos;
|
int iPos[3], iFnd, iCtr, i, lastPos;
|
||||||
|
@ -300,17 +291,18 @@ bool boinc_filelist(const std::string directory,
|
||||||
strFullPath = strUserDir + strFile;
|
strFullPath = strUserDir + strFile;
|
||||||
// only add if the file really exists (i.e. not a directory)
|
// only add if the file really exists (i.e. not a directory)
|
||||||
if (is_file(strFullPath.c_str())) {
|
if (is_file(strFullPath.c_str())) {
|
||||||
ZipFileEntry zfe(strFullPath, ucSort);
|
pList->push_back(strFullPath);
|
||||||
pList->push_back(zfe);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort by file creation time
|
// sort by file creation time
|
||||||
|
if (pList->size()>1) { // sort if list is greather than 1
|
||||||
std::sort(pList->begin(), pList->end()); // may as well sort it?
|
std::sort(pList->begin(), pList->end(), StringVectorSort); // may as well sort it?
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *BOINC_RCSID_bdf38b2dfb = "$Id$";
|
const char *BOINC_RCSID_bdf38b2dfb = "$Id$";
|
||||||
|
|
||||||
|
|
|
@ -32,21 +32,7 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class ZipFileEntry :public std::string
|
typedef std::vector<std::string> ZipFileList;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
// forward declarations for boinc_zip functions
|
// forward declarations for boinc_zip functions
|
||||||
// note it's basically like running zip/unzip, just comprise an argc/argv
|
// note it's basically like running zip/unzip, just comprise an argc/argv
|
||||||
|
@ -77,6 +63,3 @@ extern
|
||||||
#endif
|
#endif
|
||||||
int boinc_zip(int bZipType, const char* szFileZip, const char* szFileIn);
|
int boinc_zip(int bZipType, const char* szFileZip, const char* szFileIn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue