DATADIR = datadir;
CACHEID = cacheid;
+ if ( cacheid.find("_") != -1 ) {
+ if(log) *log << "CCACHE: Invalid cacheid \"" << cacheid << "\" given. Cacheids must not contain underscores!" << endl << flush;
+ exit(1);
+ }
+
configMem = (char*)malloc(configMemSize);
tmpConfig = (char*)malloc(configMemSize);
inchar = new char [infile.size()+1];
strcpy (inchar, infile.c_str());
-
+
inParts = strtok( inchar, "_" );
for(int iPart=0; inParts!=NULL; iPart++)
{
switch(iPart)
{
- case 1: if(inParts != CACHEID) return false; break;
- case 2:
+ case 1: if(inParts != CACHEID)
+ return false;
+ break;
+ case 2:
if (atoi(inParts) > NEQUI)
return false;
else if (atoi(inParts) < NEQUI)
while(true)
{
- if( (!inFile.is_open()) && inFiles.size() == 0 ) return nequileft;
+ vector<infiledesc>::iterator inFileIt = getNextInfile(excludeFileHashes);
- while( (!inFile.is_open()) && inFiles.size() > 0 ) {
- bool excludethisfile=false;
+ if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return nequileft;
- openFileDesc = inFiles.back();
+ while( (!inFile.is_open()) && inFiles.size() > 0 ) {
+ openFileDesc = *inFileIt;
- if (excludeFileHashes != NULL)
- for (vector<unsigned long>::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit)
- if ( *exit == hash(inFiles.back().filename) ) {
- excludethisfile = true;
- break;
- }
-
- if ( ! excludethisfile ) {
- if(log) *log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush;
- inFile.open( (DATADIR + "/" + inFiles.back().filename).c_str(), std::ios::binary );
- }
- else
- if(log) *log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush;
+ if(log) *log << "CCACHE: Opening dat-file: " << inFileIt->filename << endl << flush;
+ inFile.open( (DATADIR + "/" + inFileIt->filename).c_str(), std::ios::binary );
- inFiles.pop_back();
+ inFiles.erase(inFileIt);
if( !inFile.is_open() ) continue;
headerStore.pop_back();
}
}
+
+vector<infiledesc>::iterator configcache::getNextInfile(vector<unsigned long> *excludeFileHashes) {
+ for (vector<infiledesc>::iterator init = inFiles.begin(); init != inFiles.end(); ++init) {
+ if (excludeFileHashes != NULL) {
+ bool excludethisfile = false;
+
+ for (vector<unsigned long>::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit)
+ if ( *exit == hash(init->filename) ) {
+ excludethisfile = true;
+ break;
+ }
+
+ if (excludethisfile)
+ continue;
+ }
+ return init;
+ }
+ return inFiles.end();
+}