]> git.saurik.com Git - apt.git/blame - apt-pkg/indexfile.h
implement Fallback-Of for IndexTargets
[apt.git] / apt-pkg / indexfile.h
CommitLineData
b2e465d6
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b2e465d6
AL
3/* ######################################################################
4
5 Index File - Abstraction for an index of archive/source file.
6
a52f938b 7 There are 4 primary sorts of index files, all represented by this
b2e465d6
AL
8 class:
9
10 Binary index files
a52f938b 11 Binary translation files
1e3f4083 12 Binary index files describing the local system
b2e465d6
AL
13 Source index files
14
15 They are all bundled together here, and the interfaces for
16 sources.list, acquire, cache gen and record parsing all use this class
1e3f4083 17 to access the underlying representation.
b2e465d6
AL
18
19 ##################################################################### */
20 /*}}}*/
21#ifndef PKGLIB_INDEXFILE_H
22#define PKGLIB_INDEXFILE_H
23
b2e465d6
AL
24#include <apt-pkg/srcrecords.h>
25#include <apt-pkg/pkgrecords.h>
453b82a3
DK
26#include <apt-pkg/pkgcache.h>
27#include <apt-pkg/cacheiterators.h>
472ff00e 28#include <apt-pkg/macros.h>
0a843901 29
e3c1cfc7 30#include <map>
453b82a3
DK
31#include <string>
32
a4f6bdc8
DK
33#ifndef APT_8_CLEANER_HEADERS
34using std::string;
35#endif
453b82a3 36#ifndef APT_10_CLEANER_HEADERS
b2e465d6 37class pkgAcquire;
453b82a3
DK
38#endif
39
b2e465d6 40class pkgCacheGenerator;
c9443c01 41class pkgCacheListParser;
b2e465d6 42class OpProgress;
472ff00e 43
e3c1cfc7
DK
44class IndexTarget /*{{{*/
45/** \brief Information about an index file. */
46{
47 public:
48 /** \brief A URI from which the index file can be downloaded. */
49 std::string URI;
50
51 /** \brief A description of the index file. */
52 std::string Description;
53
54 /** \brief A shorter description of the index file. */
55 std::string ShortDesc;
56
57 /** \brief The key by which this index file should be
58 looked up within the meta index file. */
59 std::string MetaKey;
60
61 /** \brief Is it okay if the file isn't found in the meta index */
62 bool IsOptional;
63
653ef26c
DK
64 /** \brief If the file is downloaded compressed, do not unpack it */
65 bool KeepCompressed;
66
001c76fe
DK
67 /** \brief options with which this target was created
68 Prefer the usage of #Option if at all possible.
69 Beware: Not all of these options are intended for public use */
e3c1cfc7
DK
70 std::map<std::string, std::string> Options;
71
72 IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
73 std::string const &LongDesc, std::string const &URI, bool const IsOptional,
653ef26c 74 bool const KeepCompressed, std::map<std::string, std::string> const &Options);
e3c1cfc7 75
001c76fe
DK
76 enum OptionKeys {
77 SITE,
78 RELEASE,
79 COMPONENT,
80 LANGUAGE,
81 ARCHITECTURE,
82 BASE_URI,
83 REPO_URI,
84 CREATED_BY,
8881b11e
DK
85 TARGET_OF,
86 FILENAME,
3fd89e62 87 EXISTING_FILENAME,
1a3a14ac 88 PDIFFS,
d7a51997 89 COMPRESSIONTYPES,
9adb9778 90 DEFAULTENABLED,
3090ae69 91 SOURCESENTRY,
24e8f24e 92 BY_HASH,
0179cfa8 93 KEEPCOMPRESSEDAS,
7f2d1eef 94 FALLBACK_OF,
001c76fe
DK
95 };
96 std::string Option(OptionKeys const Key) const;
1a3a14ac 97 bool OptionBool(OptionKeys const Key) const;
8881b11e 98 std::string Format(std::string format) const;
e3c1cfc7
DK
99};
100 /*}}}*/
101
b2e465d6
AL
102class pkgIndexFile
103{
6c55f07a 104 void * const d;
7db98ffc
MZ
105 protected:
106 bool Trusted;
e3c1cfc7 107
b2e465d6
AL
108 public:
109
110 class Type
111 {
112 public:
e3c1cfc7 113
b2e465d6
AL
114 // Global list of Items supported
115 static Type **GlobalList;
116 static unsigned long GlobalListLen;
c9443c01 117 static Type *GetType(const char * const Type) APT_PURE;
b2e465d6
AL
118
119 const char *Label;
120
c9443c01
DK
121 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &/*File*/) const {return 0;};
122 virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &/*File*/) const {return 0;};
b2e465d6 123 Type();
0432d731 124 virtual ~Type() {};
b2e465d6
AL
125 };
126
127 virtual const Type *GetType() const = 0;
128
129 // Return descriptive strings of various sorts
c9443c01 130 virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const;
8f3ba4e8 131 virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
b2e465d6 132 pkgSrcRecords::File const &File) const;
c9443c01 133 virtual std::string Describe(bool const Short = false) const = 0;
b2e465d6
AL
134
135 // Interface for acquire
c9443c01 136 virtual std::string ArchiveURI(std::string const &/*File*/) const {return std::string();};
b2e465d6
AL
137
138 // Interface for the record parsers
139 virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
140
141 // Interface for the Cache Generator
142 virtual bool Exists() const = 0;
143 virtual bool HasPackages() const = 0;
144 virtual unsigned long Size() const = 0;
c9443c01 145 virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* const /*Prog*/) { return true; };
b2e465d6 146 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
7db98ffc 147
5dd00edb
DK
148 APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool TranslationsAvailable();
149 /* No intern need for this method anymore as the check for correctness
150 is already done in getLanguages(). Note also that this check is
151 rather bad (doesn't take three character like ast into account).*/
152 APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool CheckLanguageCode(const char * const Lang);
153 /* As we have now possibly more than one LanguageCode this method is
154 superseeded by a) private classmembers or b) getLanguages() */
155 APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static std::string LanguageCode();
a52f938b 156
7db98ffc 157 bool IsTrusted() const { return Trusted; };
e3c1cfc7 158
c9443c01 159 explicit pkgIndexFile(bool const Trusted);
c8a4ce6c 160 virtual ~pkgIndexFile();
b2e465d6
AL
161};
162
c9443c01
DK
163class pkgDebianIndexFile : public pkgIndexFile
164{
165protected:
166 virtual std::string IndexFileName() const = 0;
167 virtual std::string GetComponent() const = 0;
168 virtual std::string GetArchitecture() const = 0;
169 virtual std::string GetProgressDescription() const = 0;
170 virtual uint8_t GetIndexFlags() const = 0;
171 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) = 0;
172 APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg);
173
174public:
175 virtual bool Merge(pkgCacheGenerator &Gen, OpProgress* const Prog) APT_OVERRIDE;
176 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE;
177
258b9e51 178 explicit pkgDebianIndexFile(bool const Trusted);
c9443c01
DK
179 virtual ~pkgDebianIndexFile();
180};
181
182class pkgDebianIndexTargetFile : public pkgDebianIndexFile
e3c1cfc7 183{
6c55f07a 184 void * const d;
e3c1cfc7
DK
185protected:
186 IndexTarget const Target;
187
c9443c01
DK
188 virtual std::string IndexFileName() const APT_OVERRIDE;
189 virtual std::string GetComponent() const APT_OVERRIDE;
190 virtual std::string GetArchitecture() const APT_OVERRIDE;
191 virtual std::string GetProgressDescription() const APT_OVERRIDE;
192 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
193
194public:
195 virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE;
196 virtual std::string Describe(bool const Short = false) const APT_OVERRIDE;
197 virtual bool Exists() const APT_OVERRIDE;
198 virtual unsigned long Size() const APT_OVERRIDE;
199
200 pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
201 virtual ~pkgDebianIndexTargetFile();
202};
203
204class pkgDebianIndexRealFile : public pkgDebianIndexFile
205{
206 void * const d;
207protected:
208 std::string File;
e3c1cfc7 209
c9443c01
DK
210 virtual std::string IndexFileName() const APT_OVERRIDE;
211 virtual std::string GetProgressDescription() const APT_OVERRIDE;
212 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
e3c1cfc7 213public:
c9443c01 214 virtual std::string Describe(bool const /*Short*/ = false) const APT_OVERRIDE;
3b302846
DK
215 virtual bool Exists() const APT_OVERRIDE;
216 virtual unsigned long Size() const APT_OVERRIDE;
c9443c01 217 virtual std::string ArchiveURI(std::string const &/*File*/) const APT_OVERRIDE;
e3c1cfc7 218
c9443c01
DK
219 pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
220 virtual ~pkgDebianIndexRealFile();
e3c1cfc7
DK
221};
222
b2e465d6 223#endif