apt: apt-pkg/indexfile.h Source File

apt 3.2.0 commandline package manager

indexfile.h
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 Index File - Abstraction for an index of archive/source file.
6
7 There are 4 primary sorts of index files, all represented by this
8 class:
9
10 Binary index files
11 Binary translation files
12 Binary index files describing the local system
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
17 to access the underlying representation.
18
19 ##################################################################### */
20 /*}}}*/
21#ifndef PKGLIB_INDEXFILE_H
22#define PKGLIB_INDEXFILE_H
23
24#include <apt-pkg/macros.h>
25#include <apt-pkg/pkgcache.h>
26#include <apt-pkg/pkgrecords.h>
27#include <apt-pkg/srcrecords.h>
28
29#include <map>
30#include <string>
31
32
33class pkgCacheGenerator;
34class pkgCacheListParser;
35class OpProgress;
36
37 class APT_PUBLIC IndexTarget /*{{{*/
39{
40 public:
42 std::string URI;
43
45 std::string Description;
46
48 std::string ShortDesc;
49
52 std::string MetaKey;
53
55 bool IsOptional;
56
58 bool KeepCompressed;
59
63 std::map<std::string, std::string> Options;
64
65 IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
66 std::string const &LongDesc, std::string const &URI, bool const IsOptional,
67 bool const KeepCompressed, std::map<std::string, std::string> const &Options);
68
69 enum OptionKeys
70 {
71 SITE,
72 RELEASE,
73 COMPONENT,
74 LANGUAGE,
75 ARCHITECTURE,
76 BASE_URI,
77 REPO_URI,
78 CREATED_BY,
79 TARGET_OF,
80 FILENAME,
81 EXISTING_FILENAME,
82 PDIFFS,
83 COMPRESSIONTYPES,
84 DEFAULTENABLED,
85 SOURCESENTRY,
86 BY_HASH,
87 KEEPCOMPRESSEDAS,
88 FALLBACK_OF,
89 IDENTIFIER,
90 ALLOW_INSECURE,
91 ALLOW_WEAK,
92 ALLOW_DOWNGRADE_TO_INSECURE,
93 INRELEASE_PATH,
94 SHADOWED,
95 };
96 std::string Option(OptionKeys const Key) const;
97 bool OptionBool(OptionKeys const Key) const;
98 std::string Format(std::string format) const;
99};
100 /*}}}*/
101
102 class APT_PUBLIC pkgIndexFile
103{
104 void * const d;
105 protected:
106 bool Trusted;
107
108 public:
109
110 class APT_PUBLIC Type
111 {
112 public:
113
114 // Global list of Items supported
115 static Type **GlobalList;
116 static unsigned long GlobalListLen;
117 static Type *GetType(const char * const Type) APT_PURE;
118
119 const char *Label;
120
121 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &/*File*/) const {return 0;};
122 virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &/*File*/) const {return 0;};
123 Type();
124 virtual ~Type() {};
125 };
126
127 virtual const Type *GetType() const = 0;
128
129 // Return descriptive strings of various sorts
130 virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const;
131 virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
132 pkgSrcRecords::File const &File) const;
133 virtual std::string Describe(bool const Short = false) const = 0;
134
135 // Interface for acquire
136 virtual std::string ArchiveURI(std::string const &/*File*/) const {return std::string();};
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;
145 virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* const /*Prog*/) { return true; };
146 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
147
148 bool IsTrusted() const { return Trusted; };
149
150 explicit pkgIndexFile(bool const Trusted);
151 virtual ~pkgIndexFile();
152};
153
154 class APT_PUBLIC pkgDebianIndexFile : public pkgIndexFile
155{
156protected:
157 virtual std::string IndexFileName() const = 0;
158 virtual std::string GetComponent() const = 0;
159 virtual std::string GetArchitecture() const = 0;
160 virtual std::string GetProgressDescription() const = 0;
161 virtual uint8_t GetIndexFlags() const = 0;
162 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) = 0;
163 APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg);
164
165public:
166 bool Merge(pkgCacheGenerator &Gen, OpProgress *Prog) override;
167 pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const override;
168
169 explicit pkgDebianIndexFile(bool const Trusted);
170 ~pkgDebianIndexFile() override;
171};
172
173 class APT_PUBLIC pkgDebianIndexTargetFile : public pkgDebianIndexFile
174{
175 friend class pkgDebianIndexFile;
176 void * const d;
177protected:
178 IndexTarget const Target;
179
180 std::string IndexFileName() const override;
181 [[nodiscard]] std::string GetComponent() const override;
182 [[nodiscard]] std::string GetArchitecture() const override;
183 [[nodiscard]] std::string GetProgressDescription() const override;
184 bool OpenListFile(FileFd &Pkg, std::string const &FileName) override;
185
186 public:
187 [[nodiscard]] std::string ArchiveURI(std::string const &File) const override;
188 [[nodiscard]] std::string Describe(bool Short = false) const override;
189 [[nodiscard]] bool Exists() const override;
190 [[nodiscard]] unsigned long Size() const override;
191 IndexTarget GetIndexTarget() const APT_HIDDEN;
192
193 pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
194 ~pkgDebianIndexTargetFile() override;
195};
196
197 class APT_PUBLIC pkgDebianIndexRealFile : public pkgDebianIndexFile
198{
199 void * const d;
200protected:
201 std::string File;
202
203 [[nodiscard]] std::string IndexFileName() const override;
204 [[nodiscard]] std::string GetProgressDescription() const override;
205 bool OpenListFile(FileFd &Pkg, std::string const &FileName) override;
206
207 public:
208 [[nodiscard]] std::string Describe(bool /*Short*/ = false) const override;
209 [[nodiscard]] bool Exists() const override;
210 [[nodiscard]] unsigned long Size() const override;
211 [[nodiscard]] std::string ArchiveURI(std::string const & /*File*/) const override;
212
213 pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
214 ~pkgDebianIndexRealFile() override;
215};
216
217#endif
FileFd
Definition fileutl.h:43
IndexTarget
Information about an index file.
Definition indexfile.h:39
IndexTarget::IsOptional
bool IsOptional
Is it okay if the file isn't found in the meta index.
Definition indexfile.h:55
IndexTarget::KeepCompressed
bool KeepCompressed
If the file is downloaded compressed, do not unpack it.
Definition indexfile.h:58
IndexTarget::Description
std::string Description
A description of the index file.
Definition indexfile.h:45
IndexTarget::ShortDesc
std::string ShortDesc
A shorter description of the index file.
Definition indexfile.h:48
IndexTarget::Options
std::map< std::string, std::string > Options
options with which this target was created Prefer the usage of Option if at all possible....
Definition indexfile.h:63
IndexTarget::URI
std::string URI
A URI from which the index file can be downloaded.
Definition indexfile.h:42
IndexTarget::MetaKey
std::string MetaKey
The key by which this index file should be looked up within the meta index file.
Definition indexfile.h:52
OpProgress
Definition progress.h:30
pkgCacheGenerator
Definition pkgcachegen.h:44
pkgCacheListParser
Definition pkgcachegen.h:181
pkgCache::PkgFileIterator
Definition cacheiterators.h:496
pkgCache::VerIterator
Definition cacheiterators.h:218
pkgCache
Definition pkgcache.h:126
pkgIndexFile::Type
Definition indexfile.h:111
pkgRecords::Parser
Definition pkgrecords.h:50
pkgSrcRecords::Parser
Definition srcrecords.h:39
pkgcache.h
pkgCache - Structure definitions for the cache file
pkgSrcRecords::File
Definition srcrecords.h:30