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();
+}