summaryrefslogtreecommitdiff
path: root/apt-pkg/indexfile.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-06-11 11:38:04 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-06-11 11:38:04 +0200
commite3c1cfc767f17f5e9b2cd99f2658db3d6ac8edd9 (patch)
tree3114a44b2499c76baea4aa24ec1b408c3e21cf3d /apt-pkg/indexfile.cc
parent1da3b7b8e15b642135b54684e70a0c271471f07a (diff)
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
Diffstat (limited to 'apt-pkg/indexfile.cc')
-rw-r--r--apt-pkg/indexfile.cc87
1 files changed, 81 insertions, 6 deletions
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<config.h>
+#include <apt-pkg/configuration.h>
#include <apt-pkg/indexfile.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cacheiterators.h>
@@ -50,25 +52,24 @@ pkgIndexFile::Type *pkgIndexFile::Type::GetType(const char *Type)
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<std::string, std::string> 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<std::string,std::string>::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<std::string> types = APT::Configuration::getCompressionTypes();
+ for (std::vector<std::string>::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());
+}
+ /*}}}*/