]> git.saurik.com Git - apt.git/blob - apt-pkg/indexfile.h
test: Avoid use of /proc/self/fd
[apt.git] / apt-pkg / 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/srcrecords.h>
25 #include <apt-pkg/pkgrecords.h>
26 #include <apt-pkg/pkgcache.h>
27 #include <apt-pkg/cacheiterators.h>
28 #include <apt-pkg/macros.h>
29
30 #include <map>
31 #include <string>
32
33 #ifndef APT_8_CLEANER_HEADERS
34 using std::string;
35 #endif
36 #ifndef APT_10_CLEANER_HEADERS
37 class pkgAcquire;
38 #endif
39
40 class pkgCacheGenerator;
41 class pkgCacheListParser;
42 class OpProgress;
43
44 class 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
64 /** \brief If the file is downloaded compressed, do not unpack it */
65 bool KeepCompressed;
66
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 */
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,
74 bool const KeepCompressed, std::map<std::string, std::string> const &Options);
75
76 enum OptionKeys {
77 SITE,
78 RELEASE,
79 COMPONENT,
80 LANGUAGE,
81 ARCHITECTURE,
82 BASE_URI,
83 REPO_URI,
84 CREATED_BY,
85 TARGET_OF,
86 FILENAME,
87 EXISTING_FILENAME,
88 PDIFFS,
89 COMPRESSIONTYPES,
90 DEFAULTENABLED,
91 SOURCESENTRY,
92 BY_HASH,
93 KEEPCOMPRESSEDAS,
94 FALLBACK_OF,
95 IDENTIFIER,
96 ALLOW_INSECURE,
97 ALLOW_WEAK,
98 ALLOW_DOWNGRADE_TO_INSECURE,
99 };
100 std::string Option(OptionKeys const Key) const;
101 bool OptionBool(OptionKeys const Key) const;
102 std::string Format(std::string format) const;
103 };
104 /*}}}*/
105
106 class pkgIndexFile
107 {
108 void * const d;
109 protected:
110 bool Trusted;
111
112 public:
113
114 class Type
115 {
116 public:
117
118 // Global list of Items supported
119 static Type **GlobalList;
120 static unsigned long GlobalListLen;
121 static Type *GetType(const char * const Type) APT_PURE;
122
123 const char *Label;
124
125 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &/*File*/) const {return 0;};
126 virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &/*File*/) const {return 0;};
127 Type();
128 virtual ~Type() {};
129 };
130
131 virtual const Type *GetType() const = 0;
132
133 // Return descriptive strings of various sorts
134 virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const;
135 virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
136 pkgSrcRecords::File const &File) const;
137 virtual std::string Describe(bool const Short = false) const = 0;
138
139 // Interface for acquire
140 virtual std::string ArchiveURI(std::string const &/*File*/) const {return std::string();};
141
142 // Interface for the record parsers
143 virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
144
145 // Interface for the Cache Generator
146 virtual bool Exists() const = 0;
147 virtual bool HasPackages() const = 0;
148 virtual unsigned long Size() const = 0;
149 virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* const /*Prog*/) { return true; };
150 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
151
152 APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool TranslationsAvailable();
153 /* No intern need for this method anymore as the check for correctness
154 is already done in getLanguages(). Note also that this check is
155 rather bad (doesn't take three character like ast into account).*/
156 APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool CheckLanguageCode(const char * const Lang);
157 /* As we have now possibly more than one LanguageCode this method is
158 superseeded by a) private classmembers or b) getLanguages() */
159 APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static std::string LanguageCode();
160
161 bool IsTrusted() const { return Trusted; };
162
163 explicit pkgIndexFile(bool const Trusted);
164 virtual ~pkgIndexFile();
165 };
166
167 class pkgDebianIndexFile : public pkgIndexFile
168 {
169 protected:
170 virtual std::string IndexFileName() const = 0;
171 virtual std::string GetComponent() const = 0;
172 virtual std::string GetArchitecture() const = 0;
173 virtual std::string GetProgressDescription() const = 0;
174 virtual uint8_t GetIndexFlags() const = 0;
175 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) = 0;
176 APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg);
177
178 public:
179 virtual bool Merge(pkgCacheGenerator &Gen, OpProgress* const Prog) APT_OVERRIDE;
180 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE;
181
182 explicit pkgDebianIndexFile(bool const Trusted);
183 virtual ~pkgDebianIndexFile();
184 };
185
186 class pkgDebianIndexTargetFile : public pkgDebianIndexFile
187 {
188 void * const d;
189 protected:
190 IndexTarget const Target;
191
192 virtual std::string IndexFileName() const APT_OVERRIDE;
193 virtual std::string GetComponent() const APT_OVERRIDE;
194 virtual std::string GetArchitecture() const APT_OVERRIDE;
195 virtual std::string GetProgressDescription() const APT_OVERRIDE;
196 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
197
198 public:
199 virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE;
200 virtual std::string Describe(bool const Short = false) const APT_OVERRIDE;
201 virtual bool Exists() const APT_OVERRIDE;
202 virtual unsigned long Size() const APT_OVERRIDE;
203
204 pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
205 virtual ~pkgDebianIndexTargetFile();
206 };
207
208 class pkgDebianIndexRealFile : public pkgDebianIndexFile
209 {
210 void * const d;
211 protected:
212 std::string File;
213
214 virtual std::string IndexFileName() const APT_OVERRIDE;
215 virtual std::string GetProgressDescription() const APT_OVERRIDE;
216 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
217 public:
218 virtual std::string Describe(bool const /*Short*/ = false) const APT_OVERRIDE;
219 virtual bool Exists() const APT_OVERRIDE;
220 virtual unsigned long Size() const APT_OVERRIDE;
221 virtual std::string ArchiveURI(std::string const &/*File*/) const APT_OVERRIDE;
222
223 pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
224 virtual ~pkgDebianIndexRealFile();
225 };
226
227 #endif