00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <Basics.H>
00025 #include <FS.H>
00026 #include "SMultiPKFileRep.H"
00027 #include "StatError.H"
00028 #include "StatNames.H"
00029 #include "StatDirEntry.H"
00030 #include "StatPKFile.H"
00031 #include "StatMPKFile.H"
00032
00033 using std::ifstream;
00034 using std::cout;
00035 using std::endl;
00036
00037 int MPKFileObj::Search(int verbose, Stat::Collection &stats)
00038 throw (StatError::BadMPKFile,
00039 StatError::EndOfFile, FS::Failure, FS::DoesNotExist)
00040 {
00041 if (verbose >= 2) {
00042 cout << " " << this->fname << endl;
00043 }
00044
00045
00046 ifstream ifs;
00047 FS::OpenReadOnly(this->fname, ifs);
00048 try {
00049 try {
00050 this->hdr = NEW_CONSTR(SMultiPKFileRep::Header, (ifs));
00051 this->hdr->ReadEntries(ifs);
00052 this->hdr->ReadPKFiles(ifs);
00053 }
00054 catch (SMultiPKFileRep::BadMPKFile) {
00055 throw (StatError::BadMPKFile(this->fname));
00056 }
00057 catch (FS::EndOfFile) {
00058 throw (StatError::EndOfFile(this->fname));
00059 }
00060 }
00061 catch (...) {
00062 FS::Close(ifs);
00063 throw;
00064 }
00065 FS::Close(ifs);
00066
00067
00068 int cnt;
00069 {
00070 PKFileObj *pkf = (PKFileObj *) 0;
00071 MPKFileIter it(this);
00072 for (cnt = 0; it.Next( pkf); cnt++) {
00073 (void) pkf->Search(verbose, stats);
00074 }
00075 pkf = (PKFileObj *) 0;
00076 }
00077
00078
00079 stats.entryStats[Stat::MPKFileSize].AddVal(this->hdr->totalLen, this->loc);
00080
00081
00082 int thisLevel = 3;
00083 StatCount *sc;
00084 if (stats.fanout.size() <= thisLevel) {
00085 assert(stats.fanout.size() == thisLevel);
00086 sc = NEW(StatCount);
00087 stats.fanout.addhi(sc);
00088 } else {
00089 sc = stats.fanout.get(thisLevel);
00090 }
00091 sc->AddVal(cnt, this->loc);
00092 return thisLevel;
00093 }
00094
00095 bool MPKFileIter::Next( PKFileObj* &pkf) throw ()
00096 {
00097 const SMultiPKFileRep::Header *hdr = this->mpkf->hdr;
00098 bool res = (this->pkIndex < hdr->num);
00099 if (res) {
00100 SMultiPKFileRep::HeaderEntry *he;
00101 FP::Tag *fpPtr = hdr->pkSeq[this->pkIndex++];
00102 bool inTbl = hdr->pkTbl.Get(*fpPtr, he);
00103 assert(inTbl);
00104 pkf = NEW_CONSTR(PKFileObj, (*(mpkf->loc), he));
00105 }
00106 return res;
00107 }