diff options
Diffstat (limited to 'apt-pkg')
49 files changed, 490 insertions, 301 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index d798c7107..9433e5c4a 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -683,17 +683,17 @@ bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/ // remove all patches until the next matching patch is found // this requires the Index file to be ordered for(vector<DiffInfo>::iterator I=available_patches.begin(); - available_patches.size() > 0 && + available_patches.empty() == false && I != available_patches.end() && - (*I).sha1 != local_sha1; - I++) + I->sha1 != local_sha1; + ++I) { available_patches.erase(I); } // error checking and falling back if no patch was found - if(available_patches.size() == 0) - { + if(available_patches.empty() == true) + { Failed("", NULL); return false; } @@ -758,7 +758,7 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size,string Md5Has chmod(FinalFile.c_str(),0644); // see if there is more to download - if(available_patches.size() > 0) { + if(available_patches.empty() == false) { new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc, ExpectedHash, ServerSha1, available_patches); return Finish(); @@ -810,6 +810,13 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target, if (CompressionExtension.empty() == false) CompressionExtension.erase(CompressionExtension.end()-1); + // only verify non-optional targets, see acquire-item.h for a FIXME + // to make this more flexible + if (Target->IsOptional()) + Verify = false; + else + Verify = true; + Init(Target->URI, Target->Description, Target->ShortDesc); } /*}}}*/ @@ -907,6 +914,7 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash, /* Verify the index file for correctness (all indexes must * have a Package field) (LP: #346386) (Closes: #627642) */ + if (Verify == true) { FileFd fd(DestFile, FileFd::ReadOnly); pkgTagSection sec; @@ -1260,8 +1268,9 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,string Hash, / if (SigFile == "") { // There was no signature file, so we are finished. Download - // the indexes without verification. - QueueIndexes(false); + // the indexes and do only hashsum verification + MetaIndexParser->Load(DestFile); + QueueIndexes(true); } else { @@ -1376,7 +1385,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ #endif for (vector <struct IndexTarget*>::const_iterator Target = IndexTargets->begin(); Target != IndexTargets->end(); - Target++) + ++Target) { HashString ExpectedIndexHash; if (verify) @@ -1398,6 +1407,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ { std::cerr << "Queueing: " << (*Target)->URI << std::endl; std::cerr << "Expected Hash: " << ExpectedIndexHash.toStr() << std::endl; + std::cerr << "For: " << Record->MetaKeyFilename << std::endl; } if (ExpectedIndexHash.empty() == true && (*Target)->IsOptional() == false) { @@ -1673,7 +1683,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, // check if we have one trusted source for the package. if so, switch // to "TrustedOnly" mode - for (pkgCache::VerFileIterator i = Version.FileList(); i.end() == false; i++) + for (pkgCache::VerFileIterator i = Version.FileList(); i.end() == false; ++i) { pkgIndexFile *Index; if (Sources->FindIndex(i.File(),Index) == false) @@ -1710,7 +1720,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, bool pkgAcqArchive::QueueNext() { string const ForceHash = _config->Find("Acquire::ForceHash"); - for (; Vf.end() == false; Vf++) + for (; Vf.end() == false; ++Vf) { // Ignore not source sources if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0) @@ -1825,7 +1835,7 @@ bool pkgAcqArchive::QueueNext() Desc.ShortDesc = Version.ParentPkg().Name(); QueueURI(Desc); - Vf++; + ++Vf; return true; } return false; @@ -1899,7 +1909,7 @@ void pkgAcqArchive::Failed(string Message,pkgAcquire::MethodConfig *Cnf) StringToBool(LookupTag(Message,"Transient-Failure"),false) == true) { // Vf = Version.FileList(); - while (Vf.end() == false) Vf++; + while (Vf.end() == false) ++Vf; StoreFilename = string(); Item::Failed(Message,Cnf); return; @@ -2073,13 +2083,3 @@ string pkgAcqFile::Custom600Headers() return ""; } /*}}}*/ -bool IndexTarget::IsOptional() const { - if (strncmp(ShortDesc.c_str(), "Translation", 11) != 0) - return false; - return true; -} -bool IndexTarget::IsSubIndex() const { - if (ShortDesc != "TranslationIndex") - return false; - return true; -} diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index e6916a834..13be17a01 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -559,6 +559,16 @@ class pkgAcqIndex : public pkgAcquire::Item */ bool Erase; + /** \brief Verify for correctness by checking if a "Package" + * tag is found in the index. This can be set to + * false for optional index targets + * + */ + // FIXME: instead of a bool it should use a verify string that will + // then be used in the pkgAcqIndex::Done method to ensure that + // the downloaded file contains the expected tag + bool Verify; + /** \brief The download request that is currently being * processed. */ @@ -646,8 +656,9 @@ class pkgAcqIndexTrans : public pkgAcqIndex }; /*}}}*/ /** \brief Information about an index file. */ /*{{{*/ -struct IndexTarget +class IndexTarget { + public: /** \brief A URI from which the index file can be downloaded. */ string URI; @@ -662,14 +673,28 @@ struct IndexTarget */ string MetaKey; - //FIXME: We should use virtual methods here instead… - bool IsOptional() const; - bool IsSubIndex() const; + virtual bool IsOptional() const { + return false; + } + virtual bool IsSubIndex() const { + return false; + } }; /*}}}*/ /** \brief Information about an optional index file. */ /*{{{*/ -struct OptionalIndexTarget : public IndexTarget +class OptionalIndexTarget : public IndexTarget +{ + virtual bool IsOptional() const { + return true; + } +}; + /*}}}*/ +/** \brief Information about an subindex index file. */ /*{{{*/ +class SubIndexTarget : public IndexTarget { + virtual bool IsSubIndex() const { + return true; + } }; /*}}}*/ diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index 69f7b1c57..1ae139b40 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -83,7 +83,7 @@ void pkgAcqMethod::Fail(bool Transient) void pkgAcqMethod::Fail(string Err,bool Transient) { // Strip out junk from the error messages - for (string::iterator I = Err.begin(); I != Err.end(); I++) + for (string::iterator I = Err.begin(); I != Err.end(); ++I) { if (*I == '\r') *I = ' '; @@ -427,12 +427,8 @@ void pkgAcqMethod::Status(const char *Format,...) to keep the pipeline synchronized. */ void pkgAcqMethod::Redirect(const string &NewURI) { - std::cout << "103 Redirect\nURI: "; - if (Queue != 0) - std::cout << Queue->Uri << "\n"; - else - std::cout << "<UNKNOWN>\n"; - std::cout << "New-URI: " << NewURI << "\n" + std::cout << "103 Redirect\nURI: " << Queue->Uri << "\n" + << "New-URI: " << NewURI << "\n" << "\n" << std::flush; // Change the URI for the request. diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index e33dbb5d5..3a547fb3a 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -118,7 +118,7 @@ pkgAcquire::~pkgAcquire() /* */ void pkgAcquire::Shutdown() { - while (Items.size() != 0) + while (Items.empty() == false) { if (Items[0]->Status == Item::StatFetching) Items[0]->Status = Item::StatError; @@ -157,7 +157,7 @@ void pkgAcquire::Remove(Item *Itm) I = Items.begin(); } else - I++; + ++I; } } /*}}}*/ @@ -413,7 +413,7 @@ pkgAcquire::RunResult pkgAcquire::Run(int PulseIntervall) I->Shutdown(false); // Shut down the items - for (ItemIterator I = Items.begin(); I != Items.end(); I++) + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) (*I)->Finished(); if (_error->PendingError()) @@ -469,7 +469,7 @@ bool pkgAcquire::Clean(string Dir) // Look in the get list ItemCIterator I = Items.begin(); - for (; I != Items.end(); I++) + for (; I != Items.end(); ++I) if (flNotDir((*I)->DestFile) == Dir->d_name) break; @@ -490,7 +490,7 @@ bool pkgAcquire::Clean(string Dir) unsigned long long pkgAcquire::TotalNeeded() { unsigned long long Total = 0; - for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) + for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I) Total += (*I)->FileSize; return Total; } @@ -501,7 +501,7 @@ unsigned long long pkgAcquire::TotalNeeded() unsigned long long pkgAcquire::FetchNeeded() { unsigned long long Total = 0; - for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) + for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I) if ((*I)->Local == false) Total += (*I)->FileSize; return Total; @@ -513,7 +513,7 @@ unsigned long long pkgAcquire::FetchNeeded() unsigned long long pkgAcquire::PartialPresent() { unsigned long long Total = 0; - for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) + for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I) if ((*I)->Local == false) Total += (*I)->PartialSize; return Total; @@ -783,11 +783,11 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) unsigned int Unknown = 0; unsigned int Count = 0; for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); I != Owner->ItemsEnd(); - I++, Count++) + ++I, ++Count) { TotalItems++; if ((*I)->Status == pkgAcquire::Item::StatDone) - CurrentItems++; + ++CurrentItems; // Totally ignore local items if ((*I)->Local == true) @@ -797,7 +797,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) if ((*I)->Complete == true) CurrentBytes += (*I)->FileSize; if ((*I)->FileSize == 0 && (*I)->Complete == false) - Unknown++; + ++Unknown; } // Compute the current completion @@ -851,7 +851,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) char msg[200]; long i = CurrentItems < TotalItems ? CurrentItems + 1 : CurrentItems; - unsigned long long const ETA = (TotalBytes - CurrentBytes) / CurrentCPS; + unsigned long long ETA = 0; + if(CurrentCPS > 0) + ETA = (TotalBytes - CurrentBytes) / CurrentCPS; // only show the ETA if it makes sense if (ETA > 0 && ETA < 172800 /* two days */ ) diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index c9eaa67d1..ae555df22 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -349,6 +349,8 @@ class pkgAcquire */ bool Setup(pkgAcquireStatus *Progress = NULL, string const &Lock = ""); + void SetLog(pkgAcquireStatus *Progress) { Log = Progress; } + /** \brief Construct a new pkgAcquire. */ pkgAcquire(pkgAcquireStatus *Log) __deprecated; pkgAcquire(); diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index d5652791c..40368c91f 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -96,7 +96,7 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/) Sim.MarkInstall(Pkg,false); // Look for broken conflicts+predepends. - for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++) + for (PkgIterator I = Sim.PkgBegin(); I.end() == false; ++I) { if (Sim[I].InstallVer == 0) continue; @@ -145,7 +145,7 @@ bool pkgSimulate::Configure(PkgIterator iPkg) Sim.Update(); // Print out each package and the failed dependencies - for (pkgCache::DepIterator D = Sim[Pkg].InstVerIter(Sim).DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = Sim[Pkg].InstVerIter(Sim).DependsList(); D.end() == false; ++D) { if (Sim.IsImportantDep(D) == false || (Sim[D] & pkgDepCache::DepInstall) != 0) @@ -209,7 +209,7 @@ bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge) void pkgSimulate::ShortBreaks() { cout << " ["; - for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++) + for (PkgIterator I = Sim.PkgBegin(); I.end() == false; ++I) { if (Sim[I].InstBroken() == true) { @@ -231,7 +231,7 @@ bool pkgApplyStatus(pkgDepCache &Cache) { pkgDepCache::ActionGroup group(Cache); - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (I->VersionList == 0) continue; @@ -300,13 +300,13 @@ bool pkgFixBroken(pkgDepCache &Cache) pkgDepCache::ActionGroup group(Cache); // Auto upgrade all broken packages - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (Cache[I].NowBroken() == true) Cache.MarkInstall(I, true, 0, false); /* Fix packages that are in a NeedArchive state but don't have a downloadable install version */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (I.State() != pkgCache::PkgIterator::NeedsUnpack || Cache[I].Delete() == true) @@ -349,19 +349,19 @@ bool pkgDistUpgrade(pkgDepCache &Cache) /* Auto upgrade all installed packages, this provides the basis for the installation */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, true, 0, false); /* Now, auto upgrade all essential packages - this ensures that the essential packages are present and working */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) Cache.MarkInstall(I, true, 0, false); /* We do it again over all previously installed packages to force conflict resolution on them all. */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, false, 0, false); @@ -370,7 +370,7 @@ bool pkgDistUpgrade(pkgDepCache &Cache) // Hold back held packages. if (_config->FindB("APT::Ignore-Hold",false) == false) { - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (I->SelectedState == pkgCache::State::Hold) { @@ -404,7 +404,7 @@ bool pkgAllUpgrade(pkgDepCache &Cache) return false; // Upgrade all installed packages - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].Install() == true) Fix.Protect(I); @@ -438,7 +438,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) do { Change = false; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { // Not interesting if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true) @@ -455,7 +455,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) Change = true; } } - Count++; + ++Count; } while (Change == true && Count < 10); @@ -542,7 +542,7 @@ void pkgProblemResolver::MakeScores() << " AddEssential => " << AddEssential << endl; // Generate the base scores for a package based on its properties - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].InstallVer == 0) continue; @@ -569,12 +569,12 @@ void pkgProblemResolver::MakeScores() } // Now that we have the base scores we go and propogate dependencies - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].InstallVer == 0) continue; - for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; ++D) { if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) @@ -591,12 +591,12 @@ void pkgProblemResolver::MakeScores() /* Now we cause 1 level of dependency inheritance, that is we add the score of the packages that depend on the target Package. This fortifies high scoring packages */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].InstallVer == 0) continue; - for (pkgCache::DepIterator D = I.RevDependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = I.RevDependsList(); D.end() == false; ++D) { // Only do it for the install version if ((pkgCache::Version *)D.ParentVer() != Cache[D.ParentPkg()].InstallVer || @@ -611,9 +611,9 @@ void pkgProblemResolver::MakeScores() /* Now we propogate along provides. This makes the packages that provide important packages extremely important */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { - for (pkgCache::PrvIterator P = I.ProvidesList(); P.end() == false; P++) + for (pkgCache::PrvIterator P = I.ProvidesList(); P.end() == false; ++P) { // Only do it once per package if ((pkgCache::Version *)P.OwnerVer() != Cache[P.OwnerPkg()].InstallVer) @@ -624,7 +624,7 @@ void pkgProblemResolver::MakeScores() /* Protected things are pushed really high up. This number should put them ahead of everything */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if ((Flags[I->ID] & Protected) != 0) Scores[I->ID] += AddProtected; @@ -721,7 +721,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) if (Start == End) break; - Start++; + ++Start; } if (Fail == true) break; @@ -778,7 +778,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) do { Again = false; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].Install() == true) Flags[I->ID] |= PreInstalled; @@ -811,7 +811,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) would cause the removal of even lower score packages. */ SPtrArray<pkgCache::Package *> PList = new pkgCache::Package *[Size]; pkgCache::Package **PEnd = PList; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) *PEnd++ = I; This = this; qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort); @@ -931,7 +931,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) } else { - Start++; + ++Start; // We only worry about critical deps. if (Start.IsCritical() != true) continue; @@ -1180,7 +1180,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) { // See if this is the result of a hold pkgCache::PkgIterator I = Cache.PkgBegin(); - for (;I.end() != true; I++) + for (;I.end() != true; ++I) { if (Cache[I].InstBroken() == false) continue; @@ -1192,7 +1192,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) // set the auto-flags (mvo: I'm not sure if we _really_ need this) pkgCache::PkgIterator I = Cache.PkgBegin(); - for (;I.end() != true; I++) { + for (;I.end() != true; ++I) { if (Cache[I].NewInstall() && !(Flags[I->ID] & PreInstalled)) { if(_config->FindI("Debug::pkgAutoRemove",false)) { std::clog << "Resolve installed new pkg: " << I.FullName(false) @@ -1265,7 +1265,7 @@ bool pkgProblemResolver::ResolveByKeepInternal() would cause the removal of even lower score packages. */ pkgCache::Package **PList = new pkgCache::Package *[Size]; pkgCache::Package **PEnd = PList; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) *PEnd++ = I; This = this; qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort); @@ -1362,7 +1362,7 @@ bool pkgProblemResolver::ResolveByKeepInternal() if (Start == End) break; - Start++; + ++Start; } if (InstOrNewPolicyBroken(I) == false) @@ -1389,7 +1389,7 @@ void pkgProblemResolver::InstallProtect() { pkgDepCache::ActionGroup group(Cache); - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if ((Flags[I->ID] & Protected) == Protected) { @@ -1469,7 +1469,7 @@ bool ListUpdate(pkgAcquireStatus &Stat, bool Failed = false; bool TransientNetworkFailure = false; for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); - I != Fetcher.ItemsEnd(); I++) + I != Fetcher.ItemsEnd(); ++I) { if ((*I)->Status == pkgAcquire::Item::StatDone) continue; diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 71e0b8e73..e1bc94f31 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -55,7 +55,7 @@ const Configuration::getCompressionTypes(bool const &Cached) { // load the order setting into our vector std::vector<std::string> const order = _config->FindVector("Acquire::CompressionTypes::Order"); for (std::vector<std::string>::const_iterator o = order.begin(); - o != order.end(); o++) { + o != order.end(); ++o) { if ((*o).empty() == true) continue; // ignore types we have no method ready to use @@ -276,7 +276,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All, // then needed and ensure the codes are not listed twice. bool noneSeen = false; for (std::vector<string>::const_iterator l = lang.begin(); - l != lang.end(); l++) { + l != lang.end(); ++l) { if (*l == "environment") { for (std::vector<string>::const_iterator e = environment.begin(); e != environment.end(); ++e) { @@ -354,7 +354,7 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache if (archs.empty() == true || std::find(archs.begin(), archs.end(), arch) == archs.end()) - archs.push_back(arch); + archs.insert(archs.begin(), arch); // erase duplicates and empty strings for (std::vector<string>::reverse_iterator a = archs.rbegin(); diff --git a/apt-pkg/aptconfiguration.h b/apt-pkg/aptconfiguration.h index 1f0399dd2..e098d0fd6 100644 --- a/apt-pkg/aptconfiguration.h +++ b/apt-pkg/aptconfiguration.h @@ -13,6 +13,7 @@ // Include Files /*{{{*/ #include <string> #include <vector> +#include <limits> /*}}}*/ namespace APT { class Configuration { /*{{{*/ @@ -94,7 +95,7 @@ public: /*{{{*/ Compressor(char const *name, char const *extension, char const *binary, char const *compressArg, char const *uncompressArg, unsigned short const cost); - Compressor() {}; + Compressor() : Cost(std::numeric_limits<unsigned short>::max()) {}; }; /** \brief Return a vector of Compressors supported for data.tar's diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index c432cf509..392cd890e 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -311,7 +311,7 @@ void pkgCdrom::ReduceSourcelist(string CD,vector<string> &List) sort(List.begin(),List.end()); // Collect similar entries - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { // Find a space.. string::size_type Space = (*I).find(' '); @@ -323,7 +323,7 @@ void pkgCdrom::ReduceSourcelist(string CD,vector<string> &List) string Word1 = string(*I,Space,SSpace-Space); string Prefix = string(*I,0,Space); - for (vector<string>::iterator J = List.begin(); J != I; J++) + for (vector<string>::iterator J = List.begin(); J != I; ++J) { // Find a space.. string::size_type Space2 = (*J).find(' '); @@ -406,7 +406,7 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf) that were the same. */ bool pkgCdrom::WriteSourceList(string Name,vector<string> &List,bool Source) { - if (List.size() == 0) + if (List.empty() == true) return true; string File = _config->FindFile("Dir::Etc::sourcelist"); @@ -456,7 +456,7 @@ bool pkgCdrom::WriteSourceList(string Name,vector<string> &List,bool Source) if (First == true) { - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { string::size_type Space = (*I).find(' '); if (Space == string::npos) @@ -490,7 +490,7 @@ bool pkgCdrom::WriteSourceList(string Name,vector<string> &List,bool Source) // Just in case the file was empty if (First == true) { - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { string::size_type Space = (*I).find(' '); if (Space == string::npos) @@ -662,13 +662,13 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ if (_config->FindB("Debug::aptcdrom",false) == true) { cout << "I found (binary):" << endl; - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) cout << *I << endl; cout << "I found (source):" << endl; - for (vector<string>::iterator I = SourceList.begin(); I != SourceList.end(); I++) + for (vector<string>::iterator I = SourceList.begin(); I != SourceList.end(); ++I) cout << *I << endl; cout << "I found (Signatures):" << endl; - for (vector<string>::iterator I = SigList.begin(); I != SigList.end(); I++) + for (vector<string>::iterator I = SigList.begin(); I != SigList.end(); ++I) cout << *I << endl; } @@ -689,7 +689,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ log->Update(msg.str(), STEP_SCAN); } - if (List.size() == 0 && SourceList.size() == 0) + if (List.empty() == true && SourceList.empty() == true) { if (_config->FindB("APT::CDROM::NoMount",false) == false) UnmountCdrom(CDROM); @@ -713,7 +713,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ { // Escape special characters string::iterator J = Name.begin(); - for (; J != Name.end(); J++) + for (; J != Name.end(); ++J) if (*J == '"' || *J == ']' || *J == '[') *J = '_'; @@ -758,7 +758,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ // Escape special characters string::iterator J = Name.begin(); - for (; J != Name.end(); J++) + for (; J != Name.end(); ++J) if (*J == '"' || *J == ']' || *J == '[') *J = '_'; @@ -805,7 +805,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ if(log != NULL) log->Update(_("Source list entries for this disc are:\n")); - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { string::size_type Space = (*I).find(' '); if (Space == string::npos) @@ -824,7 +824,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ } } - for (vector<string>::iterator I = SourceList.begin(); I != SourceList.end(); I++) + for (vector<string>::iterator I = SourceList.begin(); I != SourceList.end(); ++I) { string::size_type Space = (*I).find(' '); if (Space == string::npos) @@ -875,9 +875,7 @@ pkgUdevCdromDevices::Dlopen() /*{{{*/ libudev_handle = h; udev_new = (udev* (*)(void)) dlsym(h, "udev_new"); udev_enumerate_add_match_property = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_property"); -#if 0 // FIXME: uncomment on next ABI break udev_enumerate_add_match_sysattr = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_sysattr"); -#endif udev_enumerate_scan_devices = (int (*)(udev_enumerate*))dlsym(h, "udev_enumerate_scan_devices"); udev_enumerate_get_list_entry = (udev_list_entry* (*)(udev_enumerate*))dlsym(h, "udev_enumerate_get_list_entry"); udev_device_new_from_syspath = (udev_device* (*)(udev*, const char*))dlsym(h, "udev_device_new_from_syspath"); @@ -891,10 +889,8 @@ pkgUdevCdromDevices::Dlopen() /*{{{*/ return true; } /*}}}*/ - /*{{{*/ -// compatiblity only with the old API/ABI, can be removed on the next -// ABI break +// convenience interface, this will just call ScanForRemovable vector<CdromDevice> pkgUdevCdromDevices::Scan() { @@ -919,10 +915,6 @@ pkgUdevCdromDevices::ScanForRemovable(bool CdromOnly) if (CdromOnly) udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1"); else { -#if 1 // FIXME: remove the next two lines on the next ABI break - int (*udev_enumerate_add_match_sysattr)(struct udev_enumerate *udev_enumerate, const char *property, const char *value); - udev_enumerate_add_match_sysattr = (int (*)(udev_enumerate*, const char*, const char*))dlsym(libudev_handle, "udev_enumerate_add_match_sysattr"); -#endif udev_enumerate_add_match_sysattr(enumerate, "removable", "1"); } diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h index e83c38582..614062cbb 100644 --- a/apt-pkg/cdrom.h +++ b/apt-pkg/cdrom.h @@ -92,9 +92,7 @@ class pkgUdevCdromDevices /*{{{*/ struct udev_enumerate *(*udev_enumerate_new) (struct udev *udev); struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *list_entry); const char* (*udev_device_get_property_value)(struct udev_device *udev_device, const char *key); -#if 0 // FIXME: uncomment on next ABI break int (*udev_enumerate_add_match_sysattr)(struct udev_enumerate *udev_enumerate, const char *property, const char *value); -#endif // end libudev dlopen public: @@ -104,11 +102,11 @@ class pkgUdevCdromDevices /*{{{*/ // try to open bool Dlopen(); - // this is the new interface - vector<CdromDevice> ScanForRemovable(bool CdromOnly); - // FIXME: compat with the old interface/API/ABI only + // convenience interface, this will just call ScanForRemovable + // with "APT::cdrom::CdromOnly" vector<CdromDevice> Scan(); + vector<CdromDevice> ScanForRemovable(bool CdromOnly); }; /*}}}*/ diff --git a/apt-pkg/clean.cc b/apt-pkg/clean.cc index 2e5fd675a..1f96e941b 100644 --- a/apt-pkg/clean.cc +++ b/apt-pkg/clean.cc @@ -87,12 +87,12 @@ bool pkgArchiveCleaner::Go(string Dir,pkgCache &Cache) if (P.end() != true) { pkgCache::VerIterator V = P.VersionList(); - for (; V.end() == false; V++) + for (; V.end() == false; ++V) { // See if we can fetch this version at all bool IsFetchable = false; for (pkgCache::VerFileIterator J = V.FileList(); - J.end() == false; J++) + J.end() == false; ++J) { if (CleanInstalled == true && (J.File()->Flags & pkgCache::Flag::NotSource) != 0) diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 7f30f132d..9de795b60 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -260,7 +260,9 @@ string FindMountPointForDevice(const char *devnode) if(TokSplitString(' ', buf, out, 10)) { fclose(f); - return string(out[1]); + // unescape the \0XXX chars in the path + string mount_point = out[1]; + return DeEscapeString(mount_point); } } } diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index b3e9d8863..0f7b37ee9 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -348,7 +348,7 @@ void Configuration::Set(const char *Name,const string &Value) // Configuration::Set - Set an integer value /*{{{*/ // --------------------------------------------------------------------- /* */ -void Configuration::Set(const char *Name,int const Value) +void Configuration::Set(const char *Name,int const &Value) { Item *Itm = Lookup(Name,true); if (Itm == 0) @@ -675,9 +675,9 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio // Put the last fragment into the buffer std::string::const_iterator NonWhitespaceStart = Start; std::string::const_iterator NonWhitespaceStop = I; - for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; NonWhitespaceStart++) + for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; ++NonWhitespaceStart) ; - for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; NonWhitespaceStop--) + for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; --NonWhitespaceStop) ; if (LineBuffer.empty() == false && NonWhitespaceStop - NonWhitespaceStart != 0) LineBuffer += ' '; @@ -853,7 +853,7 @@ bool ReadConfigDir(Configuration &Conf,const string &Dir, vector<string> const List = GetListOfFilesInDir(Dir, "conf", true, true); // Read the files - for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I) if (ReadConfigFile(Conf,*I,AsSectional,Depth) == false) return false; return true; diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 3568ce815..2844ec097 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -84,7 +84,7 @@ class Configuration void CndSet(const char *Name,const string &Value); void CndSet(const char *Name,const int Value); void Set(const char *Name,const string &Value); - void Set(const char *Name,const int Value); + void Set(const char *Name,const int &Value); inline bool Exists(const string &Name) const {return Exists(Name.c_str());}; bool Exists(const char *Name) const; diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index 56bbd1c60..122e2c809 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -194,7 +194,7 @@ bool GlobalError::PopMessage(std::string &Text) { // check if another error message is pending for (std::list<Item>::const_iterator m = Messages.begin(); - m != Messages.end(); m++) + m != Messages.end(); ++m) if (m->Type == ERROR || m->Type == FATAL) return Ret; @@ -211,7 +211,7 @@ void GlobalError::DumpErrors(std::ostream &out, MsgType const &threshold, Messages.insert(Messages.begin(), s->Messages.begin(), s->Messages.end()); for (std::list<Item>::const_iterator m = Messages.begin(); - m != Messages.end(); m++) + m != Messages.end(); ++m) if (m->Type >= threshold) out << (*m) << std::endl; Discard(); @@ -232,7 +232,7 @@ bool GlobalError::empty(MsgType const &trashhold) const { return true; for (std::list<Item>::const_iterator m = Messages.begin(); - m != Messages.end(); m++) + m != Messages.end(); ++m) if (m->Type >= trashhold) return false; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 2e62846d9..95058cbde 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -447,6 +447,17 @@ string SafeGetCWD() return S; } /*}}}*/ +// GetModificationTime - Get the mtime of the given file or -1 on error /*{{{*/ +// --------------------------------------------------------------------- +/* We return / on failure. */ +time_t GetModificationTime(string const &Path) +{ + struct stat St; + if (stat(Path.c_str(), &St) < 0) + return -1; + return St.st_mtime; +} + /*}}}*/ // flNotDir - Strip the directory from the filename /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 0f2dd4194..973a38cff 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -112,6 +112,7 @@ bool FileExists(string File); bool RealFileExists(string File); bool DirectoryExists(string const &Path) __attrib_const; bool CreateDirectory(string const &Parent, string const &Path); +time_t GetModificationTime(string const &Path); /** \brief Ensure the existence of the given Path * diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc index 456ada950..b9d0749e2 100644 --- a/apt-pkg/contrib/netrc.cc +++ b/apt-pkg/contrib/netrc.cc @@ -48,10 +48,7 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL) int specific_login = (login[0] != 0); char *home = NULL; bool netrc_alloc = false; - int state = NOTHING; - char state_login = 0; /* Found a login keyword */ - char state_password = 0; /* Found a password keyword */ int state_our_login = false; /* With specific_login, found *our* login name */ @@ -82,6 +79,10 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL) bool done = false; char netrcbuffer[256]; + int state = NOTHING; + char state_login = 0; /* Found a login keyword */ + char state_password = 0; /* Found a password keyword */ + while (!done && fgets(netrcbuffer, sizeof (netrcbuffer), file)) { tok = strtok_r (netrcbuffer, " \t\n", &tok_buf); while (!done && tok) { diff --git a/apt-pkg/contrib/sha1.cc b/apt-pkg/contrib/sha1.cc index 31c576611..b5a6a2440 100644 --- a/apt-pkg/contrib/sha1.cc +++ b/apt-pkg/contrib/sha1.cc @@ -75,10 +75,9 @@ static void SHA1Transform(uint32_t state[5],uint8_t const buffer[64]) uint32_t l[16]; } CHAR64LONG16; - CHAR64LONG16 *block; + CHAR64LONG16 workspace, *block; - uint8_t workspace[64]; - block = (CHAR64LONG16 *)workspace; + block = &workspace; memcpy(block,buffer,sizeof(workspace)); /* Copy context->state[] to working vars */ diff --git a/apt-pkg/contrib/sha256.h b/apt-pkg/contrib/sha256.h index fe2b30ac2..15146c948 100644 --- a/apt-pkg/contrib/sha256.h +++ b/apt-pkg/contrib/sha256.h @@ -3,6 +3,6 @@ #include "sha2.h" -#warn "This header is deprecated, please include sha2.h instead" +#warning "This header is deprecated, please include sha2.h instead" #endif diff --git a/apt-pkg/contrib/sha2_internal.h b/apt-pkg/contrib/sha2_internal.h index bf759ad45..d9d429c92 100644 --- a/apt-pkg/contrib/sha2_internal.h +++ b/apt-pkg/contrib/sha2_internal.h @@ -35,11 +35,6 @@ #ifndef __SHA2_H__ #define __SHA2_H__ -#ifdef __cplusplus -extern "C" { -#endif - - /* * Import u_intXX_t size_t type definitions from system headers. You * may need to change this, or define these things yourself in this @@ -189,9 +184,5 @@ char* SHA512_Data(); #endif /* NOPROTO */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* __SHA2_H__ */ diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 04226f1b4..aaf44b7ff 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -271,7 +271,7 @@ bool ParseCWord(const char *&String,string &Res) string QuoteString(const string &Str, const char *Bad) { string Res; - for (string::const_iterator I = Str.begin(); I != Str.end(); I++) + for (string::const_iterator I = Str.begin(); I != Str.end(); ++I) { if (strchr(Bad,*I) != 0 || isprint(*I) == 0 || *I == 0x25 || // percent '%' char @@ -298,7 +298,7 @@ string DeQuoteString(string::const_iterator const &begin, string::const_iterator const &end) { string Res; - for (string::const_iterator I = begin; I != end; I++) + for (string::const_iterator I = begin; I != end; ++I) { if (*I == '%' && I + 2 < end && isxdigit(I[1]) && isxdigit(I[2])) @@ -632,7 +632,7 @@ string LookupTag(const string &Message,const char *Tag,const char *Default) { // Look for a matching tag. int Length = strlen(Tag); - for (string::const_iterator I = Message.begin(); I + Length < Message.end(); I++) + for (string::const_iterator I = Message.begin(); I + Length < Message.end(); ++I) { // Found the tag if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0) @@ -640,14 +640,14 @@ string LookupTag(const string &Message,const char *Tag,const char *Default) // Find the end of line and strip the leading/trailing spaces string::const_iterator J; I += Length + 1; - for (; isspace(*I) != 0 && I < Message.end(); I++); - for (J = I; *J != '\n' && J < Message.end(); J++); - for (; J > I && isspace(J[-1]) != 0; J--); + for (; isspace(*I) != 0 && I < Message.end(); ++I); + for (J = I; *J != '\n' && J < Message.end(); ++J); + for (; J > I && isspace(J[-1]) != 0; --J); return string(I,J); } - for (; *I != '\n' && I < Message.end(); I++); + for (; *I != '\n' && I < Message.end(); ++I); } // Failed to find a match @@ -1252,7 +1252,7 @@ int tolower_ascii(int const c) bool CheckDomainList(const string &Host,const string &List) { string::const_iterator Start = List.begin(); - for (string::const_iterator Cur = List.begin(); Cur <= List.end(); Cur++) + for (string::const_iterator Cur = List.begin(); Cur <= List.end(); ++Cur) { if (Cur < List.end() && *Cur != ',') continue; @@ -1268,7 +1268,68 @@ bool CheckDomainList(const string &Host,const string &List) return false; } /*}}}*/ +// DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string DeEscapeString(const string &input) +{ + char tmp[3]; + string::const_iterator it, escape_start; + string output, octal, hex; + for (it = input.begin(); it != input.end(); ++it) + { + // just copy non-escape chars + if (*it != '\\') + { + output += *it; + continue; + } + // deal with double escape + if (*it == '\\' && + (it + 1 < input.end()) && it[1] == '\\') + { + // copy + output += *it; + // advance iterator one step further + ++it; + continue; + } + + // ensure we have a char to read + if (it + 1 == input.end()) + continue; + + // read it + ++it; + switch (*it) + { + case '0': + if (it + 2 <= input.end()) { + tmp[0] = it[1]; + tmp[1] = it[2]; + tmp[2] = 0; + output += (char)strtol(tmp, 0, 8); + it += 2; + } + break; + case 'x': + if (it + 2 <= input.end()) { + tmp[0] = it[1]; + tmp[1] = it[2]; + tmp[2] = 0; + output += (char)strtol(tmp, 0, 16); + it += 2; + } + break; + default: + // FIXME: raise exception here? + break; + } + } + return output; +} + /*}}}*/ // URI::CopyFrom - Copy from an object /*{{{*/ // --------------------------------------------------------------------- /* This parses the URI into all of its components */ @@ -1277,7 +1338,7 @@ void URI::CopyFrom(const string &U) string::const_iterator I = U.begin(); // Locate the first colon, this separates the scheme - for (; I < U.end() && *I != ':' ; I++); + for (; I < U.end() && *I != ':' ; ++I); string::const_iterator FirstColon = I; /* Determine if this is a host type URI with a leading double // @@ -1289,7 +1350,7 @@ void URI::CopyFrom(const string &U) /* Find the / indicating the end of the hostname, ignoring /'s in the square brackets */ bool InBracket = false; - for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); SingleSlash++) + for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); ++SingleSlash) { if (*SingleSlash == '[') InBracket = true; @@ -1322,11 +1383,11 @@ void URI::CopyFrom(const string &U) I = FirstColon + 1; if (I > SingleSlash) I = SingleSlash; - for (; I < SingleSlash && *I != ':'; I++); + for (; I < SingleSlash && *I != ':'; ++I); string::const_iterator SecondColon = I; // Search for the @ after the colon - for (; I < SingleSlash && *I != '@'; I++); + for (; I < SingleSlash && *I != '@'; ++I); string::const_iterator At = I; // Now write the host and user/pass diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index b32198f25..ab4b54722 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -39,6 +39,10 @@ bool ParseCWord(const char *&String,string &Res); string QuoteString(const string &Str,const char *Bad); string DeQuoteString(const string &Str); string DeQuoteString(string::const_iterator const &begin, string::const_iterator const &end); + +// unescape (\0XX and \xXX) from a string +string DeEscapeString(const string &input); + string SizeToStr(double Bytes); string TimeToStr(unsigned long Sec); string Base64Encode(const string &Str); diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 303dab796..27c1f7f32 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -354,7 +354,7 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const { string FileName = IndexFile("Packages"); pkgCache::PkgFileIterator File = Cache.FileBegin(); - for (; File.end() == false; File++) + for (; File.end() == false; ++File) { if (File.FileName() == NULL || FileName != File.FileName()) continue; @@ -542,7 +542,7 @@ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) con string FileName = IndexFile(Language); pkgCache::PkgFileIterator File = Cache.FileBegin(); - for (; File.end() == false; File++) + for (; File.end() == false; ++File) { if (FileName != File.FileName()) continue; @@ -622,7 +622,7 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const { pkgCache::PkgFileIterator File = Cache.FileBegin(); - for (; File.end() == false; File++) + for (; File.end() == false; ++File) { if (this->File != File.FileName()) continue; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 6b8fbce99..a4a974897 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -200,7 +200,7 @@ string debListParser::DescriptionLanguage() std::vector<string> const lang = APT::Configuration::getLanguages(true); for (std::vector<string>::const_iterator l = lang.begin(); - l != lang.end(); l++) + l != lang.end(); ++l) if (Section.FindS(string("Description-").append(*l).c_str()).empty() == false) return *l; @@ -458,7 +458,7 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op) * * The complete architecture, consisting of <kernel>-<cpu>. */ -static string CompleteArch(std::string& arch) { +static string CompleteArch(std::string const &arch) { if (arch == "armel") return "linux-arm"; if (arch == "armhf") return "linux-arm"; if (arch == "lpia") return "linux-i386"; @@ -497,9 +497,13 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, Package.assign(Start,I - Start); // We don't want to confuse library users which can't handle MultiArch + string const arch = _config->Find("APT::Architecture"); if (StripMultiArch == true) { size_t const found = Package.rfind(':'); - if (found != string::npos) + if (found != string::npos && + (strcmp(Package.c_str() + found, ":any") == 0 || + strcmp(Package.c_str() + found, ":native") == 0 || + strcmp(Package.c_str() + found + 1, arch.c_str()) == 0)) Package = Package.substr(0,found); } @@ -540,7 +544,6 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, if (ParseArchFlags == true) { - string arch = _config->Find("APT::Architecture"); string completeArch = CompleteArch(arch); // Parse an architecture @@ -778,7 +781,9 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, size_t len = 0; // Skip empty lines - for (; buffer[len] == '\r' && buffer[len] == '\n'; ++len); + for (; buffer[len] == '\r' && buffer[len] == '\n'; ++len) + /* nothing */ + ; if (buffer[len] == '\0') continue; @@ -792,13 +797,25 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, } // seperate the tag from the data - for (; buffer[len] != ':' && buffer[len] != '\0'; ++len); + for (; buffer[len] != ':' && buffer[len] != '\0'; ++len) + /* nothing */ + ; if (buffer[len] == '\0') continue; char* dataStart = buffer + len; - for (++dataStart; *dataStart == ' '; ++dataStart); + for (++dataStart; *dataStart == ' '; ++dataStart) + /* nothing */ + ; char* dataEnd = dataStart; - for (++dataEnd; *dataEnd != '\0'; ++dataEnd); + for (++dataEnd; *dataEnd != '\0'; ++dataEnd) + /* nothing */ + ; + // The last char should be a newline, but we can never be sure: #633350 + char* lineEnd = dataEnd; + for (--lineEnd; *lineEnd == '\r' || *lineEnd == '\n'; --lineEnd) + /* nothing */ + ; + ++lineEnd; // which datastorage need to be updated map_ptrloc* writeTo = NULL; @@ -813,7 +830,7 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, APT_PARSER_WRITETO(FileI->Label, "Label") #undef APT_PARSER_WRITETO #define APT_PARSER_FLAGIT(X) else if (strncmp(#X, buffer, len) == 0) \ - pkgTagSection::FindFlag(FileI->Flags, pkgCache::Flag:: X, dataStart, dataEnd-1); + pkgTagSection::FindFlag(FileI->Flags, pkgCache::Flag:: X, dataStart, lineEnd); APT_PARSER_FLAGIT(NotAutomatic) APT_PARSER_FLAGIT(ButAutomaticUpgrades) #undef APT_PARSER_FLAGIT diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index aaae906dd..1d3754b00 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -209,7 +209,7 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const { for (std::set<std::string>::const_iterator s = sections.begin(); s != sections.end(); ++s) { for (std::vector<std::string>::const_iterator l = lang.begin(); - l != lang.end(); l++) { + l != lang.end(); ++l) { if (*l == "none") continue; IndexTarget * Target = new OptionalIndexTarget(); Target->ShortDesc = "Translation-" + *l; @@ -239,7 +239,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const // special case for --print-uris if (GetAll) { vector <struct IndexTarget *> *targets = ComputeIndexTargets(); - for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); Target++) { + for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); ++Target) { new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description, (*Target)->ShortDesc, HashString()); } @@ -296,7 +296,7 @@ vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() { if (src != ArchEntries.end()) { vector<debSectionEntry const*> const SectionEntries = src->second; for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin(); - I != SectionEntries.end(); I++) + I != SectionEntries.end(); ++I) Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted())); } @@ -311,7 +311,7 @@ vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() { if (a->first == "source") continue; for (vector<debSectionEntry const*>::const_iterator I = a->second.begin(); - I != a->second.end(); I++) { + I != a->second.end(); ++I) { Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted(), a->first)); sections[(*I)->Section].insert(lang.begin(), lang.end()); } @@ -320,7 +320,7 @@ vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() { for (map<string, set<string> >::const_iterator s = sections.begin(); s != sections.end(); ++s) for (set<string>::const_iterator l = s->second.begin(); - l != s->second.end(); l++) { + l != s->second.end(); ++l) { if (*l == "none") continue; Indexes->push_back(new debTranslationsIndex(URI,Dist,s->first,(*l).c_str())); } @@ -369,7 +369,7 @@ class debSLTypeDebian : public pkgSourceList::Type map<string, string>::const_iterator const trusted = Options.find("trusted"); for (vector<metaIndex *>::const_iterator I = List.begin(); - I != List.end(); I++) + I != List.end(); ++I) { // We only worry about debian entries here if (strcmp((*I)->GetType(), "deb") != 0) diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index db62d6c45..4dfc8b56a 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -103,6 +103,15 @@ string debRecordParser::Maintainer() return Section.FindS("Maintainer"); } /*}}}*/ +// RecordParser::RecordField - Return the value of an arbitrary field /*{{*/ +// --------------------------------------------------------------------- +/* */ +string debRecordParser::RecordField(const char *fieldName) +{ + return Section.FindS(fieldName); +} + + /*}}}*/ // RecordParser::ShortDesc - Return a 1 line description /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -128,7 +137,7 @@ string debRecordParser::LongDesc() { vector<string> const lang = APT::Configuration::getLanguages(); for (vector<string>::const_iterator l = lang.begin(); - orig.empty() && l != lang.end(); l++) + orig.empty() && l != lang.end(); ++l) orig = Section.FindS(string("Description-").append(*l).c_str()); } diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index 9692ac94c..7868bfa3d 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -50,6 +50,9 @@ class debRecordParser : public pkgRecords::Parser virtual string Name(); virtual string Homepage(); + // An arbitrary custom field + virtual string RecordField(const char *fieldName); + virtual void GetRec(const char *&Start,const char *&Stop); debRecordParser(string FileName,pkgCache &Cache); diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 7733390c0..2c34465c0 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -230,7 +230,7 @@ bool pkgDPkgPM::SendV2Pkgs(FILE *F) fprintf(F,"\n"); // Write out the package actions in order. - for (vector<Item>::iterator I = List.begin(); I != List.end(); I++) + for (vector<Item>::iterator I = List.begin(); I != List.end(); ++I) { if(I->Pkg.end() == true) continue; @@ -352,7 +352,7 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) // Feed it the filenames. if (Version <= 1) { - for (vector<Item>::iterator I = List.begin(); I != List.end(); I++) + for (vector<Item>::iterator I = List.begin(); I != List.end(); ++I) { // Only deal with packages to be installed from .deb if (I->Op != Item::Install) @@ -707,7 +707,7 @@ bool pkgDPkgPM::OpenLog() chmod(history_name.c_str(), 0644); fprintf(d->history_out, "\nStart-Date: %s\n", timestr); string remove, purge, install, reinstall, upgrade, downgrade; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { enum { CANDIDATE, CANDIDATE_AUTO, CURRENT_CANDIDATE, CURRENT } infostring; string *line = NULL; @@ -885,14 +885,14 @@ bool pkgDPkgPM::Go(int OutStatusFd) // that will be [installed|configured|removed|purged] and add // them to the PackageOps map (the dpkg states it goes through) // and the PackageOpsTranslations (human readable strings) - for (vector<Item>::const_iterator I = List.begin(); I != List.end();I++) + for (vector<Item>::const_iterator I = List.begin(); I != List.end(); ++I) { if((*I).Pkg.end() == true) continue; string const name = (*I).Pkg.Name(); PackageOpsDone[name] = 0; - for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL; i++) + for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL; ++i) { PackageOps[name].push_back(DpkgStatesOpMap[(*I).Op][i]); PackagesTotal++; @@ -910,7 +910,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Do all actions with the same Op in one run vector<Item>::const_iterator J = I; if (TriggersPending == true) - for (; J != List.end(); J++) + for (; J != List.end(); ++J) { if (J->Op == I->Op) continue; @@ -922,7 +922,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) break; } else - for (; J != List.end() && J->Op == I->Op; J++) + for (; J != List.end() && J->Op == I->Op; ++J) /* nothing */; // Generate the argument list @@ -1028,7 +1028,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Write in the file or package names if (I->Op == Item::Install) { - for (;I != J && Size < MaxArgBytes; I++) + for (;I != J && Size < MaxArgBytes; ++I) { if (I->File[0] != '/') return _error->Error("Internal Error, Pathname to install is not absolute '%s'",I->File.c_str()); @@ -1040,7 +1040,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) { string const nativeArch = _config->Find("APT::Architecture"); unsigned long const oldSize = I->Op == Item::Configure ? Size : 0; - for (;I != J && Size < MaxArgBytes; I++) + for (;I != J && Size < MaxArgBytes; ++I) { if((*I).Pkg.end() == true) continue; @@ -1478,7 +1478,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) // log the ordering const char *ops_str[] = {"Install", "Configure","Remove","Purge"}; fprintf(report, "AptOrdering:\n"); - for (vector<Item>::iterator I = List.begin(); I != List.end(); I++) + for (vector<Item>::iterator I = List.begin(); I != List.end(); ++I) fprintf(report, " %s: %s\n", (*I).Pkg.Name(), ops_str[(*I).Op]); // attach dmesg log (to learn about segfaults) diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 8dde7c173..f816630ae 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -131,7 +131,7 @@ bool pkgDepCache::Init(OpProgress *Prog) /* Set the current state of everything. In this state all of the packages are kept exactly as is. See AllUpgrade */ int Done = 0; - for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++) + for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done) { if (Prog != 0 && Done%20 == 0) Prog->Progress(Done); @@ -294,7 +294,7 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/ // then write the ones we have not seen yet std::ostringstream ostr; - for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); pkg++) { + for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); ++pkg) { StateCache const &P = PkgState[pkg->ID]; if(P.Flags & Flag::Auto) { if (pkgs_seen.find(pkg.FullName()) != pkgs_seen.end()) { @@ -367,7 +367,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) // Check the providing packages PrvIterator P = Dep.TargetPkg().ProvidesList(); PkgIterator Pkg = Dep.ParentPkg(); - for (; P.end() != true; P++) + for (; P.end() != true; ++P) { /* Provides may never be applied against the same package (or group) if it is a conflicts. See the comment above. */ @@ -536,7 +536,7 @@ void pkgDepCache::BuildGroupOrs(VerIterator const &V) { unsigned char Group = 0; - for (DepIterator D = V.DependsList(); D.end() != true; D++) + for (DepIterator D = V.DependsList(); D.end() != true; ++D) { // Build the dependency state. unsigned char &State = DepState[D->ID]; @@ -576,7 +576,7 @@ unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check, // Compute a single dependency element (glob or) DepIterator Start = D; unsigned char State = 0; - for (bool LastOR = true; D.end() == false && LastOR == true; D++) + for (bool LastOR = true; D.end() == false && LastOR == true; ++D) { State |= DepState[D->ID]; LastOR = (D->CompareOp & Dep::Or) == Dep::Or; @@ -666,15 +666,15 @@ void pkgDepCache::Update(OpProgress *Prog) // Perform the depends pass int Done = 0; - for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++) + for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done) { if (Prog != 0 && Done%20 == 0) Prog->Progress(Done); - for (VerIterator V = I.VersionList(); V.end() != true; V++) + for (VerIterator V = I.VersionList(); V.end() != true; ++V) { unsigned char Group = 0; - for (DepIterator D = V.DependsList(); D.end() != true; D++) + for (DepIterator D = V.DependsList(); D.end() != true; ++D) { // Build the dependency state. unsigned char &State = DepState[D->ID]; @@ -711,7 +711,7 @@ void pkgDepCache::Update(OpProgress *Prog) void pkgDepCache::Update(DepIterator D) { // Update the reverse deps - for (;D.end() != true; D++) + for (;D.end() != true; ++D) { unsigned char &State = DepState[D->ID]; State = DependencyState(D); @@ -744,13 +744,13 @@ void pkgDepCache::Update(PkgIterator const &Pkg) // Update the provides map for the current ver if (Pkg->CurrentVer != 0) for (PrvIterator P = Pkg.CurrentVer().ProvidesList(); - P.end() != true; P++) + P.end() != true; ++P) Update(P.ParentPkg().RevDependsList()); // Update the provides map for the candidate ver if (PkgState[Pkg->ID].CandidateVer != 0) for (PrvIterator P = PkgState[Pkg->ID].CandidateVerIter(*this).ProvidesList(); - P.end() != true; P++) + P.end() != true; ++P) Update(P.ParentPkg().RevDependsList()); } /*}}}*/ @@ -1011,7 +1011,7 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, DepIterator Start = Dep; bool Result = true; unsigned Ors = 0; - for (bool LastOR = true; Dep.end() == false && LastOR == true; Dep++,Ors++) + for (bool LastOR = true; Dep.end() == false && LastOR == true; ++Dep, ++Ors) { LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or; @@ -1477,12 +1477,12 @@ pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator const &Pk unless they are already installed */ VerIterator Last(*(pkgCache *)this,0); - for (VerIterator I = Pkg.VersionList(); I.end() == false; I++) + for (VerIterator I = Pkg.VersionList(); I.end() == false; ++I) { if (Pkg.CurrentVer() == I) return I; - for (VerFileIterator J = I.FileList(); J.end() == false; J++) + for (VerFileIterator J = I.FileList(); J.end() == false; ++J) { if ((J.File()->Flags & Flag::NotSource) != 0) continue; @@ -1513,7 +1513,7 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep) return true; else if(Dep->Type == pkgCache::Dep::Recommends) { - if ( _config->FindB("APT::Install-Recommends", false)) + if (InstallRecommends) return true; // we suport a special mode to only install-recommends for certain // sections @@ -1524,7 +1524,7 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep) return true; } else if(Dep->Type == pkgCache::Dep::Suggests) - return _config->FindB("APT::Install-Suggests", false); + return InstallSuggests; return false; } diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index adc010c28..66cb7dbab 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -258,13 +258,21 @@ class pkgDepCache : protected pkgCache::Namespace class Policy { public: - + Policy() { + InstallRecommends = _config->FindB("APT::Install-Recommends", false); + InstallSuggests = _config->FindB("APT::Install-Suggests", false); + } + virtual VerIterator GetCandidateVer(PkgIterator const &Pkg); virtual bool IsImportantDep(DepIterator const &Dep); virtual signed short GetPriority(PkgIterator const &Pkg); virtual signed short GetPriority(PkgFileIterator const &File); virtual ~Policy() {}; + + private: + bool InstallRecommends; + bool InstallSuggests; }; private: @@ -392,7 +400,7 @@ class pkgDepCache : protected pkgCache::Namespace // @{ bool MarkKeep(PkgIterator const &Pkg, bool Soft = false, bool FromUser = true, unsigned long Depth = 0); - bool MarkDelete(PkgIterator const &Pkg, bool Purge = false, + bool MarkDelete(PkgIterator const &Pkg, bool MarkPurge = false, unsigned long Depth = 0, bool FromUser = true); bool MarkInstall(PkgIterator const &Pkg,bool AutoInst = true, unsigned long Depth = 0, bool FromUser = true, @@ -460,7 +468,7 @@ class pkgDepCache : protected pkgCache::Namespace * \param Depth recursive deep of this Marker call * \param FromUser was the remove requested by the user? */ - virtual bool IsDeleteOk(const PkgIterator &Pkg,bool Purge = false, + virtual bool IsDeleteOk(const PkgIterator &Pkg,bool MarkPurge = false, unsigned long Depth = 0, bool FromUser = true); // read persistent states diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index f52ecbbcb..4df018ef4 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -46,7 +46,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List, pkgCdromStatus *log) { OpProgress *Progress = NULL; - if (List.size() == 0) + if (List.empty() == true) return true; if(log) @@ -57,7 +57,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List, // Prepare the progress indicator off_t TotalSize = 0; - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { struct stat Buf; if (stat(string(*I + GetFileName()).c_str(),&Buf) != 0 && @@ -71,7 +71,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List, unsigned int NotFound = 0; unsigned int WrongSize = 0; unsigned int Packages = 0; - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { string OrigPath = string(*I,CDROM.length()); off_t FileSize = 0; @@ -586,13 +586,13 @@ bool SigVerify::CopyMetaIndex(string CDROM, string CDName, /*{{{*/ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList, /*{{{*/ vector<string> PkgList,vector<string> SrcList) { - if (SigList.size() == 0) + if (SigList.empty() == true) return true; bool Debug = _config->FindB("Debug::aptcdrom",false); // Read all Release files - for (vector<string>::iterator I = SigList.begin(); I != SigList.end(); I++) + for (vector<string>::iterator I = SigList.begin(); I != SigList.end(); ++I) { if(Debug) cout << "Signature verify for: " << *I << endl; @@ -636,7 +636,7 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList, // go over the Indexfiles and see if they verify // if so, remove them from our copy of the lists vector<string> keys = MetaIndex->MetaKeys(); - for (vector<string>::iterator I = keys.begin(); I != keys.end(); I++) + for (vector<string>::iterator I = keys.begin(); I != keys.end(); ++I) { if(!Verify(prefix,*I, MetaIndex)) { // something went wrong, don't copy the Release.gpg @@ -779,7 +779,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/ vector<string> &List, pkgCdromStatus *log) { OpProgress *Progress = NULL; - if (List.size() == 0) + if (List.empty() == true) return true; if(log) @@ -789,7 +789,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/ // Prepare the progress indicator off_t TotalSize = 0; - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { struct stat Buf; if (stat(string(*I).c_str(),&Buf) != 0 && @@ -803,7 +803,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/ unsigned int NotFound = 0; unsigned int WrongSize = 0; unsigned int Packages = 0; - for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::iterator I = List.begin(); I != List.end(); ++I) { string OrigPath = string(*I,CDROM.length()); off_t FileSize = 0; @@ -888,7 +888,6 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/ this->Section = &Section; string Prefix; unsigned long Hits = 0; - unsigned long Chop = 0; while (Parser.Step(Section) == true) { if(Progress) @@ -906,7 +905,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/ fclose(TargetFl); if (Debug == true) - cout << " Processed by using Prefix '" << Prefix << "' and chop " << Chop << endl; + cout << " Processed by using Prefix '" << Prefix << "' and chop " << endl; if (_config->FindB("APT::CDROM::NoAct",false) == false) { diff --git a/apt-pkg/indexfile.cc b/apt-pkg/indexfile.cc index b56d9dc6c..68e9df4c8 100644 --- a/apt-pkg/indexfile.cc +++ b/apt-pkg/indexfile.cc @@ -29,7 +29,8 @@ unsigned long pkgIndexFile::Type::GlobalListLen = 0; pkgIndexFile::Type::Type() { ItmList[GlobalListLen] = this; - GlobalListLen++; + GlobalListLen++; + Label = NULL; } /*}}}*/ // Type::GetType - Locate the type by name /*{{{*/ diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 69d6cbffd..e1f69dd65 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -26,7 +26,7 @@ SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \ contrib/cdromutl.cc contrib/crc-16.cc contrib/netrc.cc \ contrib/fileutl.cc HEADERS = mmap.h error.h configuration.h fileutl.h cmndline.h netrc.h\ - md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha2.h \ + md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha2.h sha256.h\ sha2_internal.h \ hashes.h hashsum_template.h\ macros.h weakptr.h diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index 4dcb31b7e..eb19e18db 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -147,13 +147,13 @@ bool pkgOrderList::DoRun() Depth = 0; WipeFlags(Added | AddPending | Loop | InList); - for (iterator I = List; I != End; I++) + for (iterator I = List; I != End; ++I) Flag(*I,InList); // Rebuild the main list into the temp list. iterator OldEnd = End; End = NList; - for (iterator I = List; I != OldEnd; I++) + for (iterator I = List; I != OldEnd; ++I) if (VisitNode(PkgIterator(Cache,*I)) == false) { End = OldEnd; @@ -199,7 +199,7 @@ bool pkgOrderList::OrderCritical() { clog << "** Critical Unpack ordering done" << endl; - for (iterator I = List; I != End; I++) + for (iterator I = List; I != End; ++I) { PkgIterator P(Cache,*I); if (IsNow(P) == true) @@ -224,7 +224,7 @@ bool pkgOrderList::OrderUnpack(string *FileList) WipeFlags(After); // Set the inlist flag - for (iterator I = List; I != End; I++) + for (iterator I = List; I != End; ++I) { PkgIterator P(Cache,*I); if (IsMissing(P) == true && IsNow(P) == true) @@ -272,7 +272,7 @@ bool pkgOrderList::OrderUnpack(string *FileList) { clog << "** Unpack ordering done" << endl; - for (iterator I = List; I != End; I++) + for (iterator I = List; I != End; ++I) { PkgIterator P(Cache,*I); if (IsNow(P) == true) @@ -325,7 +325,7 @@ int pkgOrderList::Score(PkgIterator Pkg) Score += ScoreImmediate; for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); - D.end() == false; D++) + D.end() == false; ++D) if (D->Type == pkgCache::Dep::PreDepends) { Score += ScorePreDepends; @@ -490,7 +490,7 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver) return true; bool Res = true; - for (PrvIterator P = Ver.ProvidesList(); P.end() == false; P++) + for (PrvIterator P = Ver.ProvidesList(); P.end() == false; ++P) Res &= (this->*F)(P.ParentPkg().RevDependsList()); return Res; } @@ -617,7 +617,7 @@ bool pkgOrderList::VisitNode(PkgIterator Pkg) Loops are preprocessed and logged. */ bool pkgOrderList::DepUnPackCrit(DepIterator D) { - for (; D.end() == false; D++) + for (; D.end() == false; ++D) { if (D.Reverse() == true) { @@ -695,7 +695,7 @@ bool pkgOrderList::DepUnPackPreD(DepIterator D) if (D.Reverse() == true) return DepUnPackCrit(D); - for (; D.end() == false; D++) + for (; D.end() == false; ++D) { if (D.IsCritical() == false) continue; @@ -738,7 +738,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) if (D.Reverse() == true) return true; - for (; D.end() == false; D++) + for (; D.end() == false; ++D) { /* Only consider the PreDepends or Depends. Depends are only considered at the lowest depth or in the case of immediate @@ -793,7 +793,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) bool pkgOrderList::DepUnPackDep(DepIterator D) { - for (; D.end() == false; D++) + for (; D.end() == false; ++D) if (D.IsCritical() == true) { if (D.Reverse() == true) @@ -848,7 +848,7 @@ bool pkgOrderList::DepConfigure(DepIterator D) if (D.Reverse() == true) return true; - for (; D.end() == false; D++) + for (; D.end() == false; ++D) if (D->Type == pkgCache::Dep::Depends) if (VisitProvides(D,false) == false) return false; @@ -870,7 +870,7 @@ bool pkgOrderList::DepRemove(DepIterator D) { if (D.Reverse() == false) return true; - for (; D.end() == false; D++) + for (; D.end() == false; ++D) if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) { // Duplication elimination, consider the current version only diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 6f9f4748f..fa28dc5b2 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -65,7 +65,7 @@ bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources, if (ordering == false) return _error->Error("Internal ordering error"); - for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) + for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) { PkgIterator Pkg(Cache,*I); FileNames[Pkg->ID] = string(); @@ -101,7 +101,7 @@ bool pkgPackageManager::FixMissing() List->SetFileList(FileNames); bool Bad = false; - for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (List->IsMissing(I) == false) continue; @@ -142,7 +142,7 @@ void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer, unsigned D = I.CurrentVer().DependsList(); } - for ( /* nothing */ ; D.end() == false; D++) + for ( /* nothing */ ; D.end() == false; ++D) if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) { if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate)) @@ -171,7 +171,7 @@ bool pkgPackageManager::CreateOrderList() static bool const NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); // Generate the list of affected packages and sort it - for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { // Ignore no-version packages if (I->VersionList == 0) @@ -231,7 +231,7 @@ bool pkgPackageManager::DepAlwaysTrue(DepIterator D) bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D, const char *Ver) { - for (;D.end() == false; D++) + for (;D.end() == false; ++D) { if (D->Type != pkgCache::Dep::Conflicts && D->Type != pkgCache::Dep::Obsoletes) @@ -264,7 +264,7 @@ bool pkgPackageManager::ConfigureAll() pkgOrderList OList(&Cache); // Populate the order list - for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) + for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) if (List->IsFlag(pkgCache::PkgIterator(Cache,*I), pkgOrderList::UnPacked) == true) OList.push_back(*I); @@ -276,7 +276,7 @@ bool pkgPackageManager::ConfigureAll() bool const ConfigurePkgs = (conf == "all"); // Perform the configuring - for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) + for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); ++I) { PkgIterator Pkg(Cache,*I); @@ -311,7 +311,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg) return false; // Perform the configuring - for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); I++) + for (pkgOrderList::iterator I = OList.begin(); I != OList.end(); ++I) { PkgIterator Pkg(Cache,*I); @@ -366,13 +366,13 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) { if (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends) { - D++; + ++D; continue; } // Grok or groups Bad = true; - for (bool LastOR = true; D.end() == false && LastOR == true; D++) + for (bool LastOR = true; D.end() == false && LastOR == true; ++D) { LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; @@ -380,7 +380,7 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth) continue; SPtrArray<Version *> VList = D.AllTargets(); - for (Version **I = VList; *I != 0 && Bad == true; I++) + for (Version **I = VList; *I != 0 && Bad == true; ++I) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -446,7 +446,7 @@ bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) if (Pkg->CurrentVer != 0) { for (DepIterator D = Pkg.RevDependsList(); D.end() == false && - IsEssential == false; D++) + IsEssential == false; ++D) if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0) IsEssential = true; @@ -566,7 +566,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) return _error->Error("Couldn't configure pre-depend %s for %s, " "probably a dependency cycle.", End.TargetPkg().Name(),Pkg.Name()); - Start++; + ++Start; } else break; @@ -599,7 +599,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate) return false; for (PrvIterator P = instVer.ProvidesList(); - P.end() == false; P++) + P.end() == false; ++P) CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion()); List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); @@ -654,7 +654,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() clog << "Done ordering" << endl; bool DoneSomething = false; - for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) + for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) { PkgIterator Pkg(Cache,*I); @@ -703,7 +703,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() return Failed; // Sanity check - for (pkgOrderList::iterator I = List->begin(); I != List->end(); I++) + for (pkgOrderList::iterator I = List->begin(); I != List->end(); ++I) { if (List->IsFlag(*I,pkgOrderList::Configured) == false) { diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 0a81cb791..94c58f1f0 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -85,6 +85,8 @@ pkgCache::Header::Header() memset(PkgHashTable,0,sizeof(PkgHashTable)); memset(GrpHashTable,0,sizeof(GrpHashTable)); memset(Pools,0,sizeof(Pools)); + + CacheFileSize = 0; } /*}}}*/ // Cache::Header::CheckSizes - Check if the two headers have same *sz /*{{{*/ @@ -156,6 +158,9 @@ bool pkgCache::ReMap(bool const &Errorchecks) HeaderP->CheckSizes(DefHeader) == false) return _error->Error(_("The package cache file is an incompatible version")); + if (Map.Size() < HeaderP->CacheFileSize) + return _error->Error(_("The package cache file is corrupted, it is too small")); + // Locate our VS.. if (HeaderP->VerSysName == 0 || (VS = pkgVersioningSystem::GetVS(StrP + HeaderP->VerSysName)) == 0) @@ -176,7 +181,7 @@ bool pkgCache::ReMap(bool const &Errorchecks) unsigned long pkgCache::sHash(const string &Str) const { unsigned long Hash = 0; - for (string::const_iterator I = Str.begin(); I != Str.end(); I++) + for (string::const_iterator I = Str.begin(); I != Str.end(); ++I) Hash = 5*Hash + tolower_ascii(*I); return Hash % _count(HeaderP->PkgHashTable); } @@ -184,7 +189,7 @@ unsigned long pkgCache::sHash(const string &Str) const unsigned long pkgCache::sHash(const char *Str) const { unsigned long Hash = 0; - for (const char *I = Str; *I != 0; I++) + for (const char *I = Str; *I != 0; ++I) Hash = 5*Hash + tolower_ascii(*I); return Hash % _count(HeaderP->PkgHashTable); } @@ -570,7 +575,7 @@ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) const virtual package libc-dev which is provided by libc5-dev and libc6-dev we must ignore libc5-dev when considering the provides list. */ PrvIterator PStart = Result.ProvidesList(); - for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); PStart++); + for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); ++PStart); // Nothing but indirect self provides if (PStart.end() == true) @@ -578,7 +583,7 @@ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) const // Check for single packages in the provides list PrvIterator P = PStart; - for (; P.end() != true; P++) + for (; P.end() != true; ++P) { // Skip over self provides if (P.OwnerPkg() == ParentPkg()) @@ -612,7 +617,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const PkgIterator DPkg = TargetPkg(); // Walk along the actual package providing versions - for (VerIterator I = DPkg.VersionList(); I.end() == false; I++) + for (VerIterator I = DPkg.VersionList(); I.end() == false; ++I) { if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false) continue; @@ -627,7 +632,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const } // Follow all provides - for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; I++) + for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; ++I) { if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false) continue; @@ -718,7 +723,7 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const /* Start at A and look for B. If B is found then A > B otherwise B was before A so A < B */ VerIterator I = *this; - for (;I.end() == false; I++) + for (;I.end() == false; ++I) if (I == B) return 1; return -1; @@ -730,7 +735,7 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const bool pkgCache::VerIterator::Downloadable() const { VerFileIterator Files = FileList(); - for (; Files.end() == false; Files++) + for (; Files.end() == false; ++Files) if ((Files.File()->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource) return true; return false; @@ -743,7 +748,7 @@ bool pkgCache::VerIterator::Downloadable() const bool pkgCache::VerIterator::Automatic() const { VerFileIterator Files = FileList(); - for (; Files.end() == false; Files++) + for (; Files.end() == false; ++Files) // Do not check ButAutomaticUpgrades here as it is kind of automatic… if ((Files.File()->Flags & pkgCache::Flag::NotAutomatic) != pkgCache::Flag::NotAutomatic) return true; @@ -758,7 +763,7 @@ pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const { VerFileIterator Files = FileList(); VerFileIterator Highest = Files; - for (; Files.end() == false; Files++) + for (; Files.end() == false; ++Files) { if (Owner->VS->CmpReleaseVer(Files.File().Version(),Highest.File().Version()) > 0) Highest = Files; @@ -775,7 +780,7 @@ string pkgCache::VerIterator::RelStr() const { bool First = true; string Res; - for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; I++) + for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; ++I) { // Do not print 'not source' entries' pkgCache::PkgFileIterator File = I.File(); @@ -784,7 +789,7 @@ string pkgCache::VerIterator::RelStr() const // See if we have already printed this out.. bool Seen = false; - for (pkgCache::VerFileIterator J = this->FileList(); I != J; J++) + for (pkgCache::VerFileIterator J = this->FileList(); I != J; ++J) { pkgCache::PkgFileIterator File2 = J.File(); if (File2->Label == 0 || File->Label == 0) @@ -885,7 +890,7 @@ pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const { std::vector<string> const lang = APT::Configuration::getLanguages(); for (std::vector<string>::const_iterator l = lang.begin(); - l != lang.end(); l++) + l != lang.end(); ++l) { pkgCache::DescIterator Desc = DescriptionList(); for (; Desc.end() == false; ++Desc) diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 9a9f79420..87912aead 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -314,6 +314,9 @@ struct pkgCache::Header map_ptrloc PkgHashTable[2*1048]; map_ptrloc GrpHashTable[2*1048]; + /** \brief Size of the complete cache file */ + unsigned long CacheFileSize; + bool CheckSizes(Header &Against) const; Header(); }; diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 1cae23134..a39aa9f59 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -97,6 +97,7 @@ pkgCacheGenerator::~pkgCacheGenerator() return; Cache.HeaderP->Dirty = false; + Cache.HeaderP->CacheFileSize = Map.Size(); Map.Sync(0,sizeof(pkgCache::Header)); } /*}}}*/ @@ -104,6 +105,9 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM if (oldMap == newMap) return; + if (_config->FindB("Debug::pkgCacheGen", false)) + std::clog << "Remaping from " << oldMap << " to " << newMap << std::endl; + Cache.ReMap(false); CurrentFile += (pkgCache::PackageFile*) newMap - (pkgCache::PackageFile*) oldMap; @@ -216,7 +220,7 @@ bool pkgCacheGenerator::MergeList(ListParser &List, // don't add a new description if we have one for the given // md5 && language - for ( ; Desc.end() == false; Desc++) + for ( ; Desc.end() == false; ++Desc) if (MD5SumValue(Desc.md5()) == CurMd5 && Desc.LanguageCode() == List.DescriptionLanguage()) duplicate=true; @@ -225,7 +229,7 @@ bool pkgCacheGenerator::MergeList(ListParser &List, for (Desc = Ver.DescriptionList(); Desc.end() == false; - LastDesc = &Desc->NextDesc, Desc++) + LastDesc = &Desc->NextDesc, ++Desc) { if (MD5SumValue(Desc.md5()) == CurMd5) { @@ -391,7 +395,7 @@ bool pkgCacheGenerator::MergeFileProvides(ListParser &List) unsigned long Hash = List.VersionHash(); pkgCache::VerIterator Ver = Pkg.VersionList(); Dynamic<pkgCache::VerIterator> DynVer(Ver); - for (; Ver.end() == false; Ver++) + for (; Ver.end() == false; ++Ver) { if (Ver->Hash == Hash && Version.c_str() == Ver.VerStr()) { @@ -507,7 +511,7 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver, // Link it to the end of the list map_ptrloc *Last = &Ver->FileList; - for (pkgCache::VerFileIterator V = Ver.FileList(); V.end() == false; V++) + for (pkgCache::VerFileIterator V = Ver.FileList(); V.end() == false; ++V) Last = &V->NextFile; VF->NextFile = *Last; *Last = VF.Index(); @@ -564,7 +568,7 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc, // Link it to the end of the list map_ptrloc *Last = &Desc->FileList; - for (pkgCache::DescFileIterator D = Desc.FileList(); D.end() == false; D++) + for (pkgCache::DescFileIterator D = Desc.FileList(); D.end() == false; ++D) Last = &D->NextFile; DF->NextFile = *Last; @@ -619,7 +623,7 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress) // Create Conflicts in between the group pkgCache::GrpIterator G = GetCache().GrpBegin(); Dynamic<pkgCache::GrpIterator> DynG(G); - for (; G.end() != true; G++) + for (; G.end() != true; ++G) { string const PkgName = G.Name(); pkgCache::PkgIterator P = G.PackageList(); @@ -630,9 +634,11 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress) Dynamic<pkgCache::PkgIterator> DynallPkg(allPkg); pkgCache::VerIterator V = P.VersionList(); Dynamic<pkgCache::VerIterator> DynV(V); - for (; V.end() != true; V++) + for (; V.end() != true; ++V) { - char const * const Arch = P.Arch(); + // copy P.Arch() into a string here as a cache remap + // in NewDepends() later may alter the pointer location + string Arch = P.Arch() == NULL ? "" : P.Arch(); map_ptrloc *OldDepLast = NULL; /* MultiArch handling introduces a lot of implicit Dependencies: - MultiArch: same → Co-Installable if they have the same version @@ -641,7 +647,7 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress) bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same); for (vector<string>::const_iterator A = archs.begin(); A != archs.end(); ++A) { - if (Arch == 0 || *A == Arch) + if (*A == Arch) continue; /* We allow only one installed arch at the time per group, therefore each group member conflicts @@ -683,7 +689,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, string const &Version, unsigned int const &Op, unsigned int const &Type, - map_ptrloc *OldDepLast) + map_ptrloc* &OldDepLast) { void const * const oldMap = Map.Data(); // Get a structure @@ -722,7 +728,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, if (OldDepLast == NULL) { OldDepLast = &Ver->DependsList; - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D) OldDepLast = &D->NextDepends; } else if (oldMap != Map.Data()) OldDepLast += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; @@ -914,8 +920,11 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S, /* This just verifies that each file in the list of index files exists, has matching attributes with the cache and the cache does not have any extra files. */ -static bool CheckValidity(const string &CacheFile, FileIterator Start, - FileIterator End,MMap **OutMap = 0) +static bool CheckValidity(const string &CacheFile, + pkgSourceList &List, + FileIterator Start, + FileIterator End, + MMap **OutMap = 0) { bool const Debug = _config->FindB("Debug::pkgCacheGen", false); // No file, certainly invalid @@ -926,6 +935,13 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start, return false; } + if (List.GetLastModifiedTime() > GetModificationTime(CacheFile)) + { + if (Debug == true) + std::clog << "sources.list is newer than the cache" << std::endl; + return false; + } + // Map it FileFd CacheF(CacheFile,FileFd::ReadOnly); SPtr<MMap> Map = new MMap(CacheF,0); @@ -942,7 +958,7 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start, verify the IMS data and check that it is on the disk too.. */ SPtrArray<bool> Visited = new bool[Cache.HeaderP->PackageFileCount]; memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount); - for (; Start != End; Start++) + for (; Start != End; ++Start) { if (Debug == true) std::clog << "Checking PkgFile " << (*Start)->Describe() << ": "; @@ -1009,7 +1025,7 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start, static unsigned long ComputeSize(FileIterator Start,FileIterator End) { unsigned long TotalSize = 0; - for (; Start != End; Start++) + for (; Start != End; ++Start) { if ((*Start)->HasPackages() == false) continue; @@ -1027,7 +1043,7 @@ static bool BuildCache(pkgCacheGenerator &Gen, FileIterator Start, FileIterator End) { FileIterator I; - for (I = Start; I != End; I++) + for (I = Start; I != End; ++I) { if ((*I)->HasPackages() == false) continue; @@ -1057,7 +1073,7 @@ static bool BuildCache(pkgCacheGenerator &Gen, Progress->Done(); TotalSize = ComputeSize(Start, End); CurrentSize = 0; - for (I = Start; I != End; I++) + for (I = Start; I != End; ++I) { unsigned long Size = (*I)->Size(); if (Progress != NULL) @@ -1104,12 +1120,12 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress vector<pkgIndexFile *> Files; for (vector<metaIndex *>::const_iterator i = List.begin(); i != List.end(); - i++) + ++i) { vector <pkgIndexFile *> *Indexes = (*i)->GetIndexFiles(); for (vector<pkgIndexFile *>::const_iterator j = Indexes->begin(); j != Indexes->end(); - j++) + ++j) Files.push_back (*j); } @@ -1151,7 +1167,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress Progress->OverallProgress(0,1,1,_("Reading package lists")); // Cache is OK, Fin. - if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true) + if (CheckValidity(CacheFile, List, Files.begin(),Files.end(),OutMap) == true) { if (Progress != NULL) Progress->OverallProgress(1,1,1,_("Reading package lists")); @@ -1204,7 +1220,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress // Lets try the source cache. unsigned long CurrentSize = 0; unsigned long TotalSize = 0; - if (CheckValidity(SrcCacheFile,Files.begin(), + if (CheckValidity(SrcCacheFile, List, Files.begin(), Files.begin()+EndOfSource) == true) { if (Debug == true) diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index ff198833a..c26051182 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -75,7 +75,7 @@ class pkgCacheGenerator /*{{{*/ bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, string const &Version, unsigned int const &Op, - unsigned int const &Type, map_ptrloc *OldDepLast); + unsigned int const &Type, map_ptrloc* &OldDepLast); unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next); map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); diff --git a/apt-pkg/pkgrecords.cc b/apt-pkg/pkgrecords.cc index 9459f7def..7709f133a 100644 --- a/apt-pkg/pkgrecords.cc +++ b/apt-pkg/pkgrecords.cc @@ -26,7 +26,7 @@ pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(Cache.HeaderP->PackageFileCount) { for (pkgCache::PkgFileIterator I = Cache.FileBegin(); - I.end() == false; I++) + I.end() == false; ++I) { const pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(I.IndexType()); if (Type == 0) diff --git a/apt-pkg/pkgrecords.h b/apt-pkg/pkgrecords.h index 840454e18..8741533b9 100644 --- a/apt-pkg/pkgrecords.h +++ b/apt-pkg/pkgrecords.h @@ -68,7 +68,10 @@ class pkgRecords::Parser /*{{{*/ virtual string LongDesc() {return string();}; virtual string Name() {return string();}; virtual string Homepage() {return string();} - + + // An arbitrary custom field + virtual string RecordField(const char *fieldName) { return string();}; + // The record in binary form virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;}; diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index 372b58a7c..e6c44ebe2 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -58,8 +58,22 @@ pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner) // The config file has a master override. string DefRel = _config->Find("APT::Default-Release"); if (DefRel.empty() == false) - CreatePin(pkgVersionMatch::Release,"",DefRel,990); - + { + bool found = false; + // FIXME: make ExpressionMatches static to use it here easily + pkgVersionMatch vm("", pkgVersionMatch::None); + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F) + { + if ((F->Archive != 0 && vm.ExpressionMatches(DefRel, F.Archive()) == true) || + (F->Codename != 0 && vm.ExpressionMatches(DefRel, F.Codename()) == true) || + (F->Version != 0 && vm.ExpressionMatches(DefRel, F.Version()) == true)) + found = true; + } + if (found == false) + _error->Error(_("The value '%s' is invalid for APT::Default-Release as such a release is not available in the sources"), DefRel.c_str()); + else + CreatePin(pkgVersionMatch::Release,"",DefRel,990); + } InitDefaults(); } /*}}}*/ @@ -69,7 +83,7 @@ pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner) bool pkgPolicy::InitDefaults() { // Initialize the priorities based on the status of the package file - for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I != Cache->FileEnd(); I++) + for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I != Cache->FileEnd(); ++I) { PFPriority[I->ID] = 500; if ((I->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource) @@ -86,10 +100,10 @@ bool pkgPolicy::InitDefaults() signed Cur = 989; StatusOverride = false; for (vector<Pin>::const_iterator I = Defaults.begin(); I != Defaults.end(); - I++, Cur--) + ++I, --Cur) { pkgVersionMatch Match(I->Data,I->Type); - for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F) { if (Match.FileMatch(F) == true && Fixed[F->ID] == false) { @@ -110,7 +124,7 @@ bool pkgPolicy::InitDefaults() } if (_config->FindB("Debug::pkgPolicy",false) == true) - for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); F++) + for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F) std::clog << "Prio of " << F.FileName() << ' ' << PFPriority[F->ID] << std::endl; return true; @@ -150,12 +164,12 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator const &Pk tracks the default when the default is taken away, and a permanent pin that stays at that setting. */ - for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; Ver++) + for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) { /* Lets see if this version is the installed version */ bool instVer = (Pkg.CurrentVer() == Ver); - for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++) + for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF) { /* If this is the status file, and the current version is not the version in the status file (ie it is not installed, or somesuch) @@ -348,7 +362,7 @@ bool ReadPinDir(pkgPolicy &Plcy,string Dir) vector<string> const List = GetListOfFilesInDir(Dir, "pref", true, true); // Read the files - for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I) if (ReadPinFile(Plcy, *I) == false) return false; return true; diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index d4eec5c8d..e20ec4704 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -175,7 +175,7 @@ pkgSourceList::pkgSourceList(string File) /* */ pkgSourceList::~pkgSourceList() { - for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) delete *I; } /*}}}*/ @@ -220,7 +220,7 @@ bool pkgSourceList::ReadMainList() /* */ void pkgSourceList::Reset() { - for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) delete *I; SrcList.erase(SrcList.begin(),SrcList.end()); } @@ -298,11 +298,11 @@ bool pkgSourceList::ReadAppend(string File) bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, pkgIndexFile *&Found) const { - for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) { vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles(); for (vector<pkgIndexFile *>::const_iterator J = Indexes->begin(); - J != Indexes->end(); J++) + J != Indexes->end(); ++J) { if ((*J)->FindInCache(*File.Cache()) == File) { @@ -320,7 +320,7 @@ bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, /* */ bool pkgSourceList::GetIndexes(pkgAcquire *Owner, bool GetAll) const { - for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) if ((*I)->GetIndexes(Owner,GetAll) == false) return false; return true; @@ -336,11 +336,33 @@ bool pkgSourceList::ReadSourceDir(string Dir) vector<string> const List = GetListOfFilesInDir(Dir, "list", true); // Read the files - for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++) + for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I) if (ReadAppend(*I) == false) return false; return true; } /*}}}*/ +// GetLastModified() /*{{{*/ +// --------------------------------------------------------------------- +/* */ +time_t pkgSourceList::GetLastModifiedTime() +{ + vector<string> List; + + string Main = _config->FindFile("Dir::Etc::sourcelist"); + string Parts = _config->FindDir("Dir::Etc::sourceparts"); + + // go over the parts + if (DirectoryExists(Parts) == true) + List = GetListOfFilesInDir(Parts, "list", true); + + // calculate the time + time_t mtime_sources = GetModificationTime(Main); + for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I) + mtime_sources = std::max(mtime_sources, GetModificationTime(*I)); + + return mtime_sources; +} + /*}}}*/ diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h index e15314a5e..7b473ee64 100644 --- a/apt-pkg/sourcelist.h +++ b/apt-pkg/sourcelist.h @@ -92,6 +92,9 @@ class pkgSourceList pkgIndexFile *&Found) const; bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const; + // query last-modified time + time_t GetLastModifiedTime(); + pkgSourceList(); pkgSourceList(string File); ~pkgSourceList(); diff --git a/apt-pkg/srcrecords.cc b/apt-pkg/srcrecords.cc index b368322f5..8c1de2ea5 100644 --- a/apt-pkg/srcrecords.cc +++ b/apt-pkg/srcrecords.cc @@ -26,11 +26,11 @@ /* Open all the source index files */ pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : Files(0), Current(0) { - for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++) + for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); ++I) { vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles(); for (vector<pkgIndexFile *>::const_iterator J = Indexes->begin(); - J != Indexes->end(); J++) + J != Indexes->end(); ++J) { Parser* P = (*J)->CreateSrcParser(); if (_error->PendingError() == true) @@ -68,7 +68,7 @@ bool pkgSrcRecords::Restart() { Current = Files.begin(); for (vector<Parser*>::iterator I = Files.begin(); - I != Files.end(); I++) + I != Files.end(); ++I) (*I)->Restart(); return true; @@ -91,7 +91,7 @@ pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOn { if (_error->PendingError() == true) return 0; - Current++; + ++Current; if (Current == Files.end()) return 0; } @@ -109,7 +109,7 @@ pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOn // Check for a binary hit const char **I = (*Current)->Binaries(); - for (; I != 0 && *I != 0; I++) + for (; I != 0 && *I != 0; ++I) if (strcmp(Package,*I) == 0) return *Current; } diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 87d070d28..28f7fcc24 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -78,7 +78,7 @@ class pkgTagSection Stop = this->Stop; }; - pkgTagSection() : Section(0), Stop(0) {}; + pkgTagSection() : Section(0), TagCount(0), Stop(0) {}; virtual ~pkgTagSection() {}; }; diff --git a/apt-pkg/vendorlist.cc b/apt-pkg/vendorlist.cc index 8432091e8..731f11acf 100644 --- a/apt-pkg/vendorlist.cc +++ b/apt-pkg/vendorlist.cc @@ -13,7 +13,7 @@ pkgVendorList::~pkgVendorList() { for (vector<const Vendor *>::const_iterator I = VendorList.begin(); - I != VendorList.end(); I++) + I != VendorList.end(); ++I) delete *I; } @@ -51,7 +51,7 @@ bool pkgVendorList::Read(string File) /*{{{*/ bool pkgVendorList::CreateList(Configuration& Cnf) /*{{{*/ { for (vector<const Vendor *>::const_iterator I = VendorList.begin(); - I != VendorList.end(); I++) + I != VendorList.end(); ++I) delete *I; VendorList.erase(VendorList.begin(),VendorList.end()); @@ -131,7 +131,7 @@ const Vendor* pkgVendorList::LookupFingerprint(string Fingerprint) /*{{{*/ /*}}}*/ const Vendor* pkgVendorList::FindVendor(const std::vector<string> GPGVOutput) /*{{{*/ { - for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); I++) + for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); ++I) { string::size_type pos = (*I).find("VALIDSIG "); if (_config->FindB("Debug::Vendor", false)) diff --git a/apt-pkg/versionmatch.cc b/apt-pkg/versionmatch.cc index c23b4c3bf..f336b3c35 100644 --- a/apt-pkg/versionmatch.cc +++ b/apt-pkg/versionmatch.cc @@ -60,7 +60,7 @@ pkgVersionMatch::pkgVersionMatch(string Data,MatchType Type) : Type(Type) // Are we a simple specification? string::const_iterator I = Data.begin(); - for (; I != Data.end() && *I != '='; I++); + for (; I != Data.end() && *I != '='; ++I); if (I == Data.end()) { // Temporary @@ -152,7 +152,7 @@ bool pkgVersionMatch::MatchVer(const char *A,string B,bool Prefix) pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg) { pkgCache::VerIterator Ver = Pkg.VersionList(); - for (; Ver.end() == false; Ver++) + for (; Ver.end() == false; ++Ver) { if (Type == Version) { @@ -163,7 +163,7 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg) continue; } - for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++) + for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF) if (FileMatch(VF.File()) == true) return Ver; } |