From 7b33ae1070f3ecff0f20745db7edeead8dfc3a05 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Dec 2013 08:18:58 +0100 Subject: refactor and move generation of the MetaIndex FileName out of the FindSrc() --- cmdline/apt-get.cc | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 3003c1971..3205fd90a 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -63,6 +63,8 @@ #include #include +#include + #include #include @@ -132,6 +134,26 @@ bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache, return true; } /*}}}*/ + +// FIXME: move into more generic code (metaindex ?) +std::string MetaIndexFileName(metaIndex *metaindex) +{ + // FIXME: this cast is the horror, the horror + debReleaseIndex *r = (debReleaseIndex*)metaindex; + + // see if we have a InRelease file + std::string PathInRelease = _config->FindDir("Dir::State::lists") + + URItoFileName(r->MetaIndexURI("InRelease")); + if (FileExists(PathInRelease)) + return PathInRelease; + + // and if not return the normal one + return _config->FindDir("Dir::State::lists") + + URItoFileName(r->MetaIndexURI("Release")); +} + + + // FindSrc - Find a source record /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -268,6 +290,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, unsigned long Offset = 0; string Version; string FoundRel; + pkgSourceList *SrcList = CacheFile.GetSourceList(); /* Iterate over all of the hits, which includes the resulting binary packages in the search */ @@ -279,10 +302,9 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, { const string Ver = Parse->Version(); - - // find release + // try to find release const pkgIndexFile& SI = Parse->Index(); - pkgSourceList *SrcList = CacheFile.GetSourceList(); + for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S) { @@ -292,11 +314,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, { if (&SI == (*IF)) { - std::string dirname = _config->FindDir("Dir::State::lists"); - std::string path; - path = dirname + URItoFileName((*S)->GetURI()) + "dists_" + (*S)->GetDist() + "_Release"; - if (!FileExists(path)) - path = dirname + URItoFileName((*S)->GetURI()) + "dists_" + (*S)->GetDist() + "_InRelease"; + std::string path = MetaIndexFileName(*S); indexRecords records; records.Load(path); if (records.GetSuite() == DefRel) -- cgit v1.2.3