Browse Source

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
tags/debian/1.1.exp9
David Kalnischkies 6 years ago
parent
commit
e3c1cfc767
7 changed files with 197 additions and 509 deletions
  1. +0
    -9
      apt-pkg/acquire-item.cc
  2. +1
    -30
      apt-pkg/acquire-item.h
  3. +35
    -346
      apt-pkg/deb/debindexfile.cc
  4. +13
    -71
      apt-pkg/deb/debindexfile.h
  5. +14
    -42
      apt-pkg/deb/debmetaindex.cc
  6. +81
    -6
      apt-pkg/indexfile.cc
  7. +53
    -5
      apt-pkg/indexfile.h

+ 0
- 9
apt-pkg/acquire-item.cc View File

@@ -382,15 +382,6 @@ bool pkgAcqDiffIndex::TransactionState(TransactionStates const state)
}
/*}}}*/

// 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)
{
}
/*}}}*/

class APT_HIDDEN NoActionItem : public pkgAcquire::Item /*{{{*/
/* The sole purpose of this class is having an item which does nothing to
reach its done state to prevent cleanup deleting the mentioned file.


+ 1
- 30
apt-pkg/acquire-item.h View File

@@ -21,6 +21,7 @@
#define PKGLIB_ACQUIRE_ITEM_H

#include <apt-pkg/acquire.h>
#include <apt-pkg/indexfile.h>
#include <apt-pkg/hashes.h>
#include <apt-pkg/weakptr.h>
#include <apt-pkg/pkgcache.h>
@@ -31,7 +32,6 @@
#include <map>

#ifndef APT_8_CLEANER_HEADERS
#include <apt-pkg/indexfile.h>
#include <apt-pkg/vendor.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/pkgrecords.h>
@@ -47,37 +47,8 @@
class indexRecords;
class pkgRecords;
class pkgSourceList;
class IndexTarget;
class pkgAcqMetaBase;

class IndexTarget /*{{{*/
/** \brief Information about an index file. */
{
public:
/** \brief A URI from which the index file can be downloaded. */
std::string URI;

/** \brief A description of the index file. */
std::string Description;

/** \brief A shorter description of the index file. */
std::string ShortDesc;

/** \brief The key by which this index file should be
looked up within the meta index file. */
std::string MetaKey;

/** \brief Is it okay if the file isn't found in the meta index */
bool IsOptional;

/** \brief Target specific options defined by the implementation */
std::map<std::string, std::string> Options;

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);
};
/*}}}*/
class pkgAcquire::Item : public WeakPointable /*{{{*/
/** \brief Represents the process by which a pkgAcquire object should
* retrieve a file or a collection of files.


+ 35
- 346
apt-pkg/deb/debindexfile.cc View File

@@ -44,8 +44,8 @@ using std::string;
// SourcesIndex::debSourcesIndex - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted) :
pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section)
debSourcesIndex::debSourcesIndex(IndexTarget const &Target,bool const Trusted) :
pkgIndexTargetFile(Target, Trusted)
{
}
/*}}}*/
@@ -56,16 +56,9 @@ debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trus
string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
pkgSrcRecords::File const &File) const
{
string Res;
Res = ::URI::ArchiveOnly(URI) + ' ';
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Res += Dist;
}
else
Res += Dist + '/' + Section;
string Res = Target.Description;
Res.erase(Target.Description.rfind(' '));

Res += " ";
Res += Record.Package();
Res += " ";
@@ -80,129 +73,19 @@ string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
/* */
pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const
{
string SourcesURI = _config->FindDir("Dir::State::lists") +
URItoFileName(IndexURI("Sources"));

std::vector<std::string> types = APT::Configuration::getCompressionTypes();
for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
{
string p;
p = SourcesURI + '.' + *t;
if (FileExists(p))
return new debSrcRecordParser(p, this);
}
string const SourcesURI = IndexFileName();
if (FileExists(SourcesURI))
return new debSrcRecordParser(SourcesURI, this);
return NULL;
}
/*}}}*/
// SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/
// ---------------------------------------------------------------------
/* */
string debSourcesIndex::Describe(bool Short) const
{
char S[300];
if (Short == true)
snprintf(S,sizeof(S),"%s",Info("Sources").c_str());
else
snprintf(S,sizeof(S),"%s (%s)",Info("Sources").c_str(),
IndexFile("Sources").c_str());
return S;
}
/*}}}*/
// SourcesIndex::Info - One liner describing the index URI /*{{{*/
// ---------------------------------------------------------------------
/* */
string debSourcesIndex::Info(const char *Type) const
{
string Info = ::URI::ArchiveOnly(URI) + ' ';
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Info += Dist;
}
else
Info += Dist + '/' + Section;
Info += " ";
Info += Type;
return Info;
}
/*}}}*/
// SourcesIndex::Index* - Return the URI to the index files /*{{{*/
// ---------------------------------------------------------------------
/* */
string debSourcesIndex::IndexFile(const char *Type) const
{
string s = URItoFileName(IndexURI(Type));

std::vector<std::string> types = APT::Configuration::getCompressionTypes();
for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
{
string p = s + '.' + *t;
if (FileExists(p))
return p;
}
return s;
}

string debSourcesIndex::IndexURI(const char *Type) const
{
string Res;
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Res = URI + Dist;
else
Res = URI;
}
else
Res = URI + "dists/" + Dist + '/' + Section +
"/source/";
Res += Type;
return Res;
}
/*}}}*/
// SourcesIndex::Exists - Check if the index is available /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debSourcesIndex::Exists() const
{
return FileExists(IndexFile("Sources"));
}
/*}}}*/
// SourcesIndex::Size - Return the size of the index /*{{{*/
// ---------------------------------------------------------------------
/* */
unsigned long debSourcesIndex::Size() const
{
unsigned long size = 0;

/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();

FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();

if (_error->PendingError() == true)
size = 0;
_error->RevertToStack();

return size;
}
/*}}}*/

// PackagesIndex::debPackagesIndex - Contructor /*{{{*/
// ---------------------------------------------------------------------
/* */
debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section,
bool const &Trusted, string const &Arch) :
pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch)
debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted) :
pkgIndexTargetFile(Target, Trusted)
{
if (Architecture == "native")
Architecture = _config->Find("APT::Architecture");
}
/*}}}*/
// PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/
@@ -210,135 +93,40 @@ debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string
/* This is a shorter version that is designed to be < 60 chars or so */
string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const
{
string Res = ::URI::ArchiveOnly(URI) + ' ';
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Res += Dist;
}
else
Res += Dist + '/' + Section;
std::string const Dist = Target.Option("RELEASE");
string Res = Target.Option("SITE") + " " + Dist;
std::string const Component = Target.Option("COMPONENT");
if (Component.empty() == false)
Res += "/" + Component;

Res += " ";
Res += Ver.ParentPkg().Name();
Res += " ";
if (Dist[Dist.size() - 1] != '/')
if (Dist.empty() == false && Dist[Dist.size() - 1] != '/')
Res.append(Ver.Arch()).append(" ");
Res += Ver.VerStr();
return Res;
}
/*}}}*/
// PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/
// ---------------------------------------------------------------------
/* This should help the user find the index in the sources.list and
in the filesystem for problem solving */
string debPackagesIndex::Describe(bool Short) const
{
char S[300];
if (Short == true)
snprintf(S,sizeof(S),"%s",Info("Packages").c_str());
else
snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(),
IndexFile("Packages").c_str());
return S;
}
/*}}}*/
// PackagesIndex::Info - One liner describing the index URI /*{{{*/
// ---------------------------------------------------------------------
/* */
string debPackagesIndex::Info(const char *Type) const
{
string Info = ::URI::ArchiveOnly(URI) + ' ';
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Info += Dist;
}
else
Info += Dist + '/' + Section;
Info += " ";
if (Dist[Dist.size() - 1] != '/')
Info += Architecture + " ";
Info += Type;
return Info;
}
/*}}}*/
// PackagesIndex::Index* - Return the URI to the index files /*{{{*/
// ---------------------------------------------------------------------
/* */
string debPackagesIndex::IndexFile(const char *Type) const
{
string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));

std::vector<std::string> types = APT::Configuration::getCompressionTypes();
for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
{
string p = s + '.' + *t;
if (FileExists(p))
return p;
}
return s;
}
string debPackagesIndex::IndexURI(const char *Type) const
{
string Res;
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Res = URI + Dist;
else
Res = URI;
}
else
Res = URI + "dists/" + Dist + '/' + Section +
"/binary-" + Architecture + '/';
Res += Type;
return Res;
}
/*}}}*/
// PackagesIndex::Exists - Check if the index is available /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debPackagesIndex::Exists() const
{
return FileExists(IndexFile("Packages"));
}
/*}}}*/
// PackagesIndex::Size - Return the size of the index /*{{{*/
// ---------------------------------------------------------------------
/* This is really only used for progress reporting. */
unsigned long debPackagesIndex::Size() const
{
unsigned long size = 0;

/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();

FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();

if (_error->PendingError() == true)
size = 0;
_error->RevertToStack();

return size;
}
/*}}}*/
// PackagesIndex::Merge - Load the index file into a cache /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
string PackageFile = IndexFile("Packages");
string const PackageFile = IndexFileName();
FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension);
debListParser Parser(&Pkg, Architecture);
debListParser Parser(&Pkg, Target.Option("ARCHITECTURE"));

if (_error->PendingError() == true)
return _error->Error("Problem opening %s",PackageFile.c_str());
if (Prog != NULL)
Prog->SubProgress(0,Info("Packages"));
Prog->SubProgress(0, Target.Description);


std::string const URI = Target.Option("REPO_URI");
std::string Dist = Target.Option("RELEASE");
if (Dist.empty())
Dist = "/";
::URI Tmp(URI);
if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false)
return _error->Error("Problem with SelectFile %s",PackageFile.c_str());
@@ -370,7 +158,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const

if (_error->PendingError() == true)
return false;
Parser.LoadReleaseInfo(File,Rel,Section);
Parser.LoadReleaseInfo(File, Rel, Target.Option("COMPONENT"));
}
return true;
@@ -381,7 +169,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
/* */
pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
{
string FileName = IndexFile("Packages");
string const FileName = IndexFileName();
pkgCache::PkgFileIterator File = Cache.FileBegin();
for (; File.end() == false; ++File)
{
@@ -411,113 +199,13 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
/*}}}*/

// TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/
// ---------------------------------------------------------------------
/* */
debTranslationsIndex::debTranslationsIndex(std::string const &URI, std::string const &Dist,
std::string const &Section, std::string const &Translation) :
pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section),
Language(Translation)
debTranslationsIndex::debTranslationsIndex(IndexTarget const &Target) :
pkgIndexTargetFile(Target, true)
{}
/*}}}*/
// TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/
// ---------------------------------------------------------------------
/* */
string debTranslationsIndex::IndexFile(const char *Type) const
{
string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));

std::vector<std::string> types = APT::Configuration::getCompressionTypes();
for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
{
string p = s + '.' + *t;
if (FileExists(p))
return p;
}
return s;
}
string debTranslationsIndex::IndexURI(const char *Type) const
{
string Res;
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Res = URI + Dist;
else
Res = URI;
}
else
Res = URI + "dists/" + Dist + '/' + Section +
"/i18n/Translation-";
Res += Type;
return Res;
}
/*}}}*/
// TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/
// ---------------------------------------------------------------------
/* This should help the user find the index in the sources.list and
in the filesystem for problem solving */
string debTranslationsIndex::Describe(bool Short) const
{
std::string S;
if (Short == true)
strprintf(S,"%s",Info(TranslationFile().c_str()).c_str());
else
strprintf(S,"%s (%s)",Info(TranslationFile().c_str()).c_str(),
IndexFile(Language.c_str()).c_str());
return S;
}
/*}}}*/
// TranslationsIndex::Info - One liner describing the index URI /*{{{*/
// ---------------------------------------------------------------------
/* */
string debTranslationsIndex::Info(const char *Type) const
{
string Info = ::URI::ArchiveOnly(URI) + ' ';
if (Dist[Dist.size() - 1] == '/')
{
if (Dist != "/")
Info += Dist;
}
else
Info += Dist + '/' + Section;
Info += " ";
Info += Type;
return Info;
}
/*}}}*/
bool debTranslationsIndex::HasPackages() const /*{{{*/
{
return FileExists(IndexFile(Language.c_str()));
}
/*}}}*/
// TranslationsIndex::Exists - Check if the index is available /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debTranslationsIndex::Exists() const
{
return FileExists(IndexFile(Language.c_str()));
}
/*}}}*/
// TranslationsIndex::Size - Return the size of the index /*{{{*/
// ---------------------------------------------------------------------
/* This is really only used for progress reporting. */
unsigned long debTranslationsIndex::Size() const
{
unsigned long size = 0;

/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();

FileFd f(IndexFile(Language.c_str()), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();

if (_error->PendingError() == true)
size = 0;
_error->RevertToStack();

return size;
return Exists();
}
/*}}}*/
// TranslationsIndex::Merge - Load the index file into a cache /*{{{*/
@@ -526,7 +214,7 @@ unsigned long debTranslationsIndex::Size() const
bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
// Check the translation file, if in use
string TranslationFile = IndexFile(Language.c_str());
string const TranslationFile = IndexFileName();
if (FileExists(TranslationFile))
{
FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension);
@@ -535,7 +223,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
return false;
if (Prog != NULL)
Prog->SubProgress(0, Info(TranslationFile.c_str()));
Prog->SubProgress(0, Target.Description);
if (Gen.SelectFile(TranslationFile,string(),*this) == false)
return _error->Error("Problem with SelectFile %s",TranslationFile.c_str());

@@ -556,8 +244,8 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
/* */
pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const
{
string FileName = IndexFile(Language.c_str());
string FileName = IndexFileName();
pkgCache::PkgFileIterator File = Cache.FileBegin();
for (; File.end() == false; ++File)
{
@@ -580,10 +268,11 @@ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) con
return pkgCache::PkgFileIterator(Cache);
}
return File;
}
}
return File;
}
/*}}}*/

// StatusIndex::debStatusIndex - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */


+ 13
- 71
apt-pkg/deb/debindexfile.h View File

@@ -30,19 +30,16 @@ class pkgCacheGenerator;

class APT_HIDDEN debStatusIndex : public pkgIndexFile
{
/** \brief dpointer placeholder (for later in case we need it) */
void *d;

protected:
std::string File;

public:

virtual const Type *GetType() const APT_CONST;
// Interface for acquire
virtual std::string Describe(bool /*Short*/) const {return File;};
// Interface for the Cache Generator
virtual bool Exists() const;
virtual bool HasPackages() const {return true;};
@@ -54,91 +51,42 @@ class APT_HIDDEN debStatusIndex : public pkgIndexFile
debStatusIndex(std::string File);
virtual ~debStatusIndex();
};
class APT_HIDDEN debPackagesIndex : public pkgIndexFile
{
/** \brief dpointer placeholder (for later in case we need it) */
void *d;

std::string URI;
std::string Dist;
std::string Section;
std::string Architecture;

APT_HIDDEN std::string Info(const char *Type) const;
APT_HIDDEN std::string IndexFile(const char *Type) const;
APT_HIDDEN std::string IndexURI(const char *Type) const;

class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile
{
public:

virtual const Type *GetType() const APT_CONST;

// Stuff for accessing files on remote items
virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
virtual std::string ArchiveURI(std::string File) const {return URI + File;};
// Interface for acquire
virtual std::string Describe(bool Short) const;

// Interface for the Cache Generator
virtual bool Exists() const;
virtual bool HasPackages() const {return true;};
virtual unsigned long Size() const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;

debPackagesIndex(std::string const &URI, std::string const &Dist, std::string const &Section,
bool const &Trusted, std::string const &Arch = "native");
debPackagesIndex(IndexTarget const &Target, bool const Trusted);
virtual ~debPackagesIndex();
};

class APT_HIDDEN debTranslationsIndex : public pkgIndexFile
class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile
{
/** \brief dpointer placeholder (for later in case we need it) */
void *d;

std::string const URI;
std::string const Dist;
std::string const Section;
std::string const Language;

APT_HIDDEN std::string Info(const char *Type) const;
APT_HIDDEN std::string IndexFile(const char *Type) const;
APT_HIDDEN std::string IndexURI(const char *Type) const;

APT_HIDDEN std::string TranslationFile() const {return std::string("Translation-").append(Language);};

public:

virtual const Type *GetType() const APT_CONST;

// Interface for acquire
virtual std::string Describe(bool Short) const;

// Interface for the Cache Generator
virtual bool Exists() const;
virtual bool HasPackages() const;
virtual unsigned long Size() const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;

debTranslationsIndex(std::string const &URI,std::string const &Dist,std::string const &Section, std::string const &Language);
debTranslationsIndex(IndexTarget const &Target);
virtual ~debTranslationsIndex();
};

class APT_HIDDEN debSourcesIndex : public pkgIndexFile
class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile
{
/** \brief dpointer placeholder (for later in case we need it) */
void *d;

std::string URI;
std::string Dist;
std::string Section;

APT_HIDDEN std::string Info(const char *Type) const;
APT_HIDDEN std::string IndexFile(const char *Type) const;
APT_HIDDEN std::string IndexURI(const char *Type) const;

public:

virtual const Type *GetType() const APT_CONST;
@@ -146,20 +94,14 @@ class APT_HIDDEN debSourcesIndex : public pkgIndexFile
// Stuff for accessing files on remote items
virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
pkgSrcRecords::File const &File) const;
virtual std::string ArchiveURI(std::string File) const {return URI + File;};
// Interface for acquire
virtual std::string Describe(bool Short) const;

// Interface for the record parsers
virtual pkgSrcRecords::Parser *CreateSrcParser() const;

// Interface for the Cache Generator
virtual bool Exists() const;
virtual bool HasPackages() const {return false;};
virtual unsigned long Size() const;
debSourcesIndex(std::string URI,std::string Dist,std::string Section,bool Trusted);

debSourcesIndex(IndexTarget const &Target, bool const Trusted);
virtual ~debSourcesIndex();
};



+ 14
- 42
apt-pkg/deb/debmetaindex.cc View File

@@ -140,6 +140,7 @@ void foreachTarget(std::string const URI, std::string const Dist,
Options.insert(std::make_pair("LANGUAGE", *l));
Options.insert(std::make_pair("ARCHITECTURE", "source"));
Options.insert(std::make_pair("BASE_URI", baseURI));
Options.insert(std::make_pair("REPO_URI", URI));
Options.insert(std::make_pair("CREATED_BY", *T));
Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options);

@@ -186,6 +187,7 @@ void foreachTarget(std::string const URI, std::string const Dist,
Options.insert(std::make_pair("LANGUAGE", *l));
Options.insert(std::make_pair("ARCHITECTURE", a->first));
Options.insert(std::make_pair("BASE_URI", baseURI));
Options.insert(std::make_pair("REPO_URI", URI));
Options.insert(std::make_pair("CREATED_BY", *T));
Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options);

@@ -294,55 +296,25 @@ bool debReleaseIndex::IsTrusted() const
return FileExists(VerifiedSigFile);
}

struct GetIndexFilesClass
std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
{
vector <pkgIndexFile *> * const Indexes;
std::string const URI;
std::string const Release;
bool const IsTrusted;
if (Indexes != NULL)
return Indexes;

void operator()(std::string const &/*URI*/, std::string const &/*ShortDesc*/, std::string const &/*LongDesc*/,
bool const /*IsOptional*/, std::map<std::string, std::string> Options)
Indexes = new std::vector<pkgIndexFile*>();
std::vector<IndexTarget> const Targets = GetIndexTargets();
bool const istrusted = IsTrusted();
for (std::vector<IndexTarget>::const_iterator T = Targets.begin(); T != Targets.end(); ++T)
{
std::string const TargetName = Options.find("CREATED_BY")->second;
std::string const TargetName = T->Options.find("CREATED_BY")->second;
if (TargetName == "Packages")
{
Indexes->push_back(new debPackagesIndex(
URI,
Release,
Options.find("COMPONENT")->second,
IsTrusted,
Options.find("ARCHITECTURE")->second
));
}
Indexes->push_back(new debPackagesIndex(*T, istrusted));
else if (TargetName == "Sources")
Indexes->push_back(new debSourcesIndex(
URI,
Release,
Options.find("COMPONENT")->second,
IsTrusted
));
Indexes->push_back(new debSourcesIndex(*T, istrusted));
else if (TargetName == "Translations")
Indexes->push_back(new debTranslationsIndex(
URI,
Release,
Options.find("COMPONENT")->second,
Options.find("LANGUAGE")->second
));
Indexes->push_back(new debTranslationsIndex(*T));
}

GetIndexFilesClass(std::string const &URI, std::string const &Release, bool const IsTrusted) :
Indexes(new vector <pkgIndexFile*>), URI(URI), Release(Release), IsTrusted(IsTrusted) {}
};

std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
{
if (Indexes != NULL)
return Indexes;

GetIndexFilesClass comp(URI, Dist, IsTrusted());
foreachTarget(URI, Dist, ArchEntries, comp);
return Indexes = comp.Indexes;
return Indexes;
}

void debReleaseIndex::PushSectionEntry(vector<string> const &Archs, const debSectionEntry *Entry) {


+ 81
- 6
apt-pkg/indexfile.cc View File

@@ -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>
@@ -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<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());
}
/*}}}*/

+ 53
- 5
apt-pkg/indexfile.h View File

@@ -28,6 +28,7 @@
#include <apt-pkg/cacheiterators.h>
#include <apt-pkg/macros.h>

#include <map>
#include <string>

#ifndef APT_8_CLEANER_HEADERS
@@ -40,17 +41,48 @@ class pkgAcquire;
class pkgCacheGenerator;
class OpProgress;

class IndexTarget /*{{{*/
/** \brief Information about an index file. */
{
public:
/** \brief A URI from which the index file can be downloaded. */
std::string URI;

/** \brief A description of the index file. */
std::string Description;

/** \brief A shorter description of the index file. */
std::string ShortDesc;

/** \brief The key by which this index file should be
looked up within the meta index file. */
std::string MetaKey;

/** \brief Is it okay if the file isn't found in the meta index */
bool IsOptional;

/** \brief Target specific options defined by the implementation */
std::map<std::string, std::string> Options;

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);

std::string Option(std::string const &Key) const;
};
/*}}}*/

class pkgIndexFile
{
protected:
bool Trusted;
public:

class Type
{
public:
// Global list of Items supported
static Type **GlobalList;
static unsigned long GlobalListLen;
@@ -70,7 +102,7 @@ class pkgIndexFile
virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
pkgSrcRecords::File const &File) const;
virtual std::string Describe(bool Short = false) const = 0;
virtual std::string Describe(bool Short = false) const = 0;

// Interface for acquire
virtual std::string ArchiveURI(std::string /*File*/) const {return std::string();};
@@ -95,9 +127,25 @@ class pkgIndexFile
static std::string LanguageCode();

bool IsTrusted() const { return Trusted; };
pkgIndexFile(bool Trusted): Trusted(Trusted) {};
pkgIndexFile(bool Trusted);
virtual ~pkgIndexFile() {};
};

class pkgIndexTargetFile : public pkgIndexFile
{
protected:
IndexTarget const Target;

std::string IndexFileName() const;

public:
virtual std::string ArchiveURI(std::string File) const;
virtual std::string Describe(bool Short = false) const;
virtual bool Exists() const;
virtual unsigned long Size() const;

pkgIndexTargetFile(IndexTarget const &Target, bool const Trusted);
};

#endif

Loading…
Cancel
Save