apt 3.0.3
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
35class OpProgress;
36
37class 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
56
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
102class 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
154class 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
174{
175 void * const d;
176protected:
177 IndexTarget const Target;
178
179 std::string IndexFileName() const override;
180 [[nodiscard]] std::string GetComponent() const override;
181 [[nodiscard]] std::string GetArchitecture() const override;
182 [[nodiscard]] std::string GetProgressDescription() const override;
183 bool OpenListFile(FileFd &Pkg, std::string const &FileName) override;
184
185 public:
186 [[nodiscard]] std::string ArchiveURI(std::string const &File) const override;
187 [[nodiscard]] std::string Describe(bool Short = false) const override;
188 [[nodiscard]] bool Exists() const override;
189 [[nodiscard]] unsigned long Size() const override;
190 IndexTarget GetIndexTarget() const APT_HIDDEN;
191
192 pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
193 ~pkgDebianIndexTargetFile() override;
194};
195
197{
198 void * const d;
199protected:
200 std::string File;
201
202 [[nodiscard]] std::string IndexFileName() const override;
203 [[nodiscard]] std::string GetProgressDescription() const override;
204 bool OpenListFile(FileFd &Pkg, std::string const &FileName) override;
205
206 public:
207 [[nodiscard]] std::string Describe(bool /*Short*/ = false) const override;
208 [[nodiscard]] bool Exists() const override;
209 [[nodiscard]] unsigned long Size() const override;
210 [[nodiscard]] std::string ArchiveURI(std::string const & /*File*/) const override;
211
212 pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
213 ~pkgDebianIndexRealFile() override;
214};
215
216#endif
Definition fileutl.h:43
Information about an index file.
Definition indexfile.h:39
bool IsOptional
Is it okay if the file isn't found in the meta index.
Definition indexfile.h:55
bool KeepCompressed
If the file is downloaded compressed, do not unpack it.
Definition indexfile.h:58
std::string Description
A description of the index file.
Definition indexfile.h:45
std::string ShortDesc
A shorter description of the index file.
Definition indexfile.h:48
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
std::string URI
A URI from which the index file can be downloaded.
Definition indexfile.h:42
std::string MetaKey
The key by which this index file should be looked up within the meta index file.
Definition indexfile.h:52
Definition progress.h:30
Definition strutl.h:220
Definition pkgcachegen.h:43
Definition pkgcachegen.h:178
Definition cacheiterators.h:47
Definition indexfile.h:155
Definition indexfile.h:197
Definition indexfile.h:174
Definition indexfile.h:111
Definition indexfile.h:103
Definition srcrecords.h:39
pkgCache - Structure definitions for the cache file
Definition srcrecords.h:30