From e3c1cfc767f17f5e9b2cd99f2658db3d6ac8edd9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Jun 2015 11:38:04 +0200 Subject: use IndexTarget to get to IndexFile Removes a bunch of duplicated code in the deb-specific parts. Especially the Description part is now handled centrally by IndexTarget instead of being duplicated to the derivations of IndexFile. Git-Dch: Ignore --- apt-pkg/indexfile.cc | 87 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 6 deletions(-) (limited to 'apt-pkg/indexfile.cc') diff --git a/apt-pkg/indexfile.cc b/apt-pkg/indexfile.cc index 89615cb41..bbcd9246c 100644 --- a/apt-pkg/indexfile.cc +++ b/apt-pkg/indexfile.cc @@ -10,8 +10,10 @@ // Include Files /*{{{*/ #include +#include #include #include +#include #include #include #include @@ -48,27 +50,26 @@ pkgIndexFile::Type *pkgIndexFile::Type::GetType(const char *Type) if (strcmp(GlobalList[I]->Label,Type) == 0) return GlobalList[I]; return 0; +} + /*}}}*/ +pkgIndexFile::pkgIndexFile(bool Trusted) : /*{{{*/ + Trusted(Trusted) +{ } /*}}}*/ // IndexFile::ArchiveInfo - Stub /*{{{*/ -// --------------------------------------------------------------------- -/* */ std::string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator /*Ver*/) const { return std::string(); } /*}}}*/ // IndexFile::FindInCache - Stub /*{{{*/ -// --------------------------------------------------------------------- -/* */ pkgCache::PkgFileIterator pkgIndexFile::FindInCache(pkgCache &Cache) const { return pkgCache::PkgFileIterator(Cache); } /*}}}*/ // IndexFile::SourceIndex - Stub /*{{{*/ -// --------------------------------------------------------------------- -/* */ std::string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &/*Record*/, pkgSrcRecords::File const &/*File*/) const { @@ -110,3 +111,77 @@ APT_DEPRECATED std::string pkgIndexFile::LanguageCode() { return APT::Configuration::getLanguages()[0]; } /*}}}*/ + +// IndexTarget - Constructor /*{{{*/ +IndexTarget::IndexTarget(std::string const &MetaKey, std::string const &ShortDesc, + std::string const &LongDesc, std::string const &URI, bool const IsOptional, + std::map const &Options) : + URI(URI), Description(LongDesc), ShortDesc(ShortDesc), MetaKey(MetaKey), IsOptional(IsOptional), Options(Options) +{ +} + /*}}}*/ +std::string IndexTarget::Option(std::string const &Key) const /*{{{*/ +{ + std::map::const_iterator const M = Options.find(Key); + if (M == Options.end()) + return ""; + return M->second; +} + /*}}}*/ + +pkgIndexTargetFile::pkgIndexTargetFile(IndexTarget const &Target, bool const Trusted) :/*{{{*/ + pkgIndexFile(Trusted), Target(Target) +{ +} + /*}}}*/ +std::string pkgIndexTargetFile::ArchiveURI(std::string File) const/*{{{*/ +{ + return Target.Option("REPO_URI") + File; +} + /*}}}*/ +std::string pkgIndexTargetFile::Describe(bool Short) const /*{{{*/ +{ + if (Short) + return Target.Description; + return Target.Description + " (" + IndexFileName() + ")"; +} + /*}}}*/ +std::string pkgIndexTargetFile::IndexFileName() const /*{{{*/ +{ + std::string const s =_config->FindDir("Dir::State::lists") + URItoFileName(Target.URI); + if (FileExists(s)) + return s; + + std::vector types = APT::Configuration::getCompressionTypes(); + for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) + { + std::string p = s + '.' + *t; + if (FileExists(p)) + return p; + } + return s; +} + /*}}}*/ +unsigned long pkgIndexTargetFile::Size() const /*{{{*/ +{ + unsigned long size = 0; + + /* we need to ignore errors here; if the lists are absent, just return 0 */ + _error->PushToStack(); + + FileFd f(IndexFileName(), FileFd::ReadOnly, FileFd::Extension); + if (!f.Failed()) + size = f.Size(); + + if (_error->PendingError() == true) + size = 0; + _error->RevertToStack(); + + return size; +} + /*}}}*/ +bool pkgIndexTargetFile::Exists() const /*{{{*/ +{ + return FileExists(IndexFileName()); +} + /*}}}*/ -- cgit v1.2.3