]>
Commit | Line | Data |
---|---|---|
b2e465d6 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
7db98ffc | 3 | // $Id: debindexfile.cc,v 1.5.2.3 2004/01/04 19:11:00 mdz Exp $ |
b2e465d6 AL |
4 | /* ###################################################################### |
5 | ||
6 | Debian Specific sources.list types and the three sorts of Debian | |
7 | index files. | |
8 | ||
9 | ##################################################################### */ | |
10 | /*}}}*/ | |
11 | // Include Files /*{{{*/ | |
ea542140 DK |
12 | #include <config.h> |
13 | ||
b2e465d6 AL |
14 | #include <apt-pkg/debindexfile.h> |
15 | #include <apt-pkg/debsrcrecords.h> | |
16 | #include <apt-pkg/deblistparser.h> | |
17 | #include <apt-pkg/debrecords.h> | |
b2e465d6 AL |
18 | #include <apt-pkg/configuration.h> |
19 | #include <apt-pkg/progress.h> | |
20 | #include <apt-pkg/error.h> | |
21 | #include <apt-pkg/strutl.h> | |
22 | #include <apt-pkg/acquire-item.h> | |
7db98ffc | 23 | #include <apt-pkg/debmetaindex.h> |
233b7808 | 24 | #include <apt-pkg/gpgv.h> |
453b82a3 DK |
25 | #include <apt-pkg/fileutl.h> |
26 | #include <apt-pkg/indexfile.h> | |
27 | #include <apt-pkg/mmap.h> | |
28 | #include <apt-pkg/pkgcache.h> | |
29 | #include <apt-pkg/cacheiterators.h> | |
30 | #include <apt-pkg/pkgcachegen.h> | |
31 | #include <apt-pkg/pkgrecords.h> | |
32 | #include <apt-pkg/srcrecords.h> | |
e011829d | 33 | |
453b82a3 DK |
34 | #include <stdio.h> |
35 | #include <iostream> | |
36 | #include <string> | |
b2e465d6 AL |
37 | #include <sys/stat.h> |
38 | /*}}}*/ | |
39 | ||
73688d27 DK |
40 | using std::string; |
41 | ||
b2e465d6 AL |
42 | // SourcesIndex::debSourcesIndex - Constructor /*{{{*/ |
43 | // --------------------------------------------------------------------- | |
44 | /* */ | |
7db98ffc MZ |
45 | debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted) : |
46 | pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section) | |
b2e465d6 AL |
47 | { |
48 | } | |
49 | /*}}}*/ | |
50 | // SourcesIndex::SourceInfo - Short 1 liner describing a source /*{{{*/ | |
51 | // --------------------------------------------------------------------- | |
52 | /* The result looks like: | |
5e02df82 | 53 | http://foo/debian/ stable/main src 1.1.1 (dsc) */ |
b2e465d6 AL |
54 | string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, |
55 | pkgSrcRecords::File const &File) const | |
56 | { | |
57 | string Res; | |
5e02df82 | 58 | Res = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
59 | if (Dist[Dist.size() - 1] == '/') |
60 | { | |
61 | if (Dist != "/") | |
62 | Res += Dist; | |
63 | } | |
64 | else | |
65 | Res += Dist + '/' + Section; | |
66 | ||
67 | Res += " "; | |
68 | Res += Record.Package(); | |
69 | Res += " "; | |
70 | Res += Record.Version(); | |
71 | if (File.Type.empty() == false) | |
72 | Res += " (" + File.Type + ")"; | |
73 | return Res; | |
74 | } | |
75 | /*}}}*/ | |
76 | // SourcesIndex::CreateSrcParser - Get a parser for the source files /*{{{*/ | |
77 | // --------------------------------------------------------------------- | |
78 | /* */ | |
79 | pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const | |
80 | { | |
94e8c9d4 | 81 | string SourcesURI = _config->FindDir("Dir::State::lists") + |
82 | URItoFileName(IndexURI("Sources")); | |
1aadba5a | 83 | |
b0f4b486 MV |
84 | std::vector<std::string> types = APT::Configuration::getCompressionTypes(); |
85 | for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t) | |
86 | { | |
87 | string p; | |
88 | p = SourcesURI + '.' + *t; | |
89 | if (FileExists(p)) | |
90 | return new debSrcRecordParser(p, this); | |
91 | } | |
92 | if (FileExists(SourcesURI)) | |
93 | return new debSrcRecordParser(SourcesURI, this); | |
94 | return NULL; | |
b2e465d6 AL |
95 | } |
96 | /*}}}*/ | |
97 | // SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/ | |
98 | // --------------------------------------------------------------------- | |
99 | /* */ | |
af87ab54 | 100 | string debSourcesIndex::Describe(bool Short) const |
b2e465d6 AL |
101 | { |
102 | char S[300]; | |
af87ab54 | 103 | if (Short == true) |
cc742108 | 104 | snprintf(S,sizeof(S),"%s",Info("Sources").c_str()); |
af87ab54 | 105 | else |
cc742108 | 106 | snprintf(S,sizeof(S),"%s (%s)",Info("Sources").c_str(), |
af87ab54 AL |
107 | IndexFile("Sources").c_str()); |
108 | ||
b2e465d6 AL |
109 | return S; |
110 | } | |
111 | /*}}}*/ | |
112 | // SourcesIndex::Info - One liner describing the index URI /*{{{*/ | |
113 | // --------------------------------------------------------------------- | |
114 | /* */ | |
115 | string debSourcesIndex::Info(const char *Type) const | |
116 | { | |
5e02df82 | 117 | string Info = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
118 | if (Dist[Dist.size() - 1] == '/') |
119 | { | |
120 | if (Dist != "/") | |
121 | Info += Dist; | |
122 | } | |
123 | else | |
124 | Info += Dist + '/' + Section; | |
125 | Info += " "; | |
126 | Info += Type; | |
127 | return Info; | |
128 | } | |
129 | /*}}}*/ | |
130 | // SourcesIndex::Index* - Return the URI to the index files /*{{{*/ | |
131 | // --------------------------------------------------------------------- | |
132 | /* */ | |
133 | inline string debSourcesIndex::IndexFile(const char *Type) const | |
134 | { | |
ec7a129e | 135 | string s = URItoFileName(IndexURI(Type)); |
b0f4b486 MV |
136 | |
137 | std::vector<std::string> types = APT::Configuration::getCompressionTypes(); | |
138 | for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t) | |
139 | { | |
140 | string p = s + '.' + *t; | |
141 | if (FileExists(p)) | |
142 | return p; | |
143 | } | |
144 | return s; | |
b2e465d6 | 145 | } |
ec7a129e | 146 | |
b2e465d6 AL |
147 | string debSourcesIndex::IndexURI(const char *Type) const |
148 | { | |
149 | string Res; | |
150 | if (Dist[Dist.size() - 1] == '/') | |
151 | { | |
152 | if (Dist != "/") | |
153 | Res = URI + Dist; | |
154 | else | |
155 | Res = URI; | |
156 | } | |
157 | else | |
158 | Res = URI + "dists/" + Dist + '/' + Section + | |
159 | "/source/"; | |
160 | ||
161 | Res += Type; | |
162 | return Res; | |
163 | } | |
164 | /*}}}*/ | |
b2e465d6 AL |
165 | // SourcesIndex::Exists - Check if the index is available /*{{{*/ |
166 | // --------------------------------------------------------------------- | |
167 | /* */ | |
168 | bool debSourcesIndex::Exists() const | |
169 | { | |
170 | return FileExists(IndexFile("Sources")); | |
171 | } | |
172 | /*}}}*/ | |
173 | // SourcesIndex::Size - Return the size of the index /*{{{*/ | |
174 | // --------------------------------------------------------------------- | |
175 | /* */ | |
176 | unsigned long debSourcesIndex::Size() const | |
177 | { | |
915f0520 MP |
178 | unsigned long size = 0; |
179 | ||
180 | /* we need to ignore errors here; if the lists are absent, just return 0 */ | |
181 | _error->PushToStack(); | |
182 | ||
f0e83599 | 183 | FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension); |
915f0520 MP |
184 | if (!f.Failed()) |
185 | size = f.Size(); | |
186 | ||
187 | if (_error->PendingError() == true) | |
188 | size = 0; | |
189 | _error->RevertToStack(); | |
5473df3f | 190 | |
915f0520 | 191 | return size; |
b2e465d6 AL |
192 | } |
193 | /*}}}*/ | |
194 | ||
195 | // PackagesIndex::debPackagesIndex - Contructor /*{{{*/ | |
196 | // --------------------------------------------------------------------- | |
197 | /* */ | |
5dd4c8b8 DK |
198 | debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section, |
199 | bool const &Trusted, string const &Arch) : | |
200 | pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch) | |
b2e465d6 | 201 | { |
5dd4c8b8 DK |
202 | if (Architecture == "native") |
203 | Architecture = _config->Find("APT::Architecture"); | |
b2e465d6 AL |
204 | } |
205 | /*}}}*/ | |
206 | // PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/ | |
207 | // --------------------------------------------------------------------- | |
208 | /* This is a shorter version that is designed to be < 60 chars or so */ | |
209 | string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const | |
210 | { | |
5e02df82 | 211 | string Res = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
212 | if (Dist[Dist.size() - 1] == '/') |
213 | { | |
214 | if (Dist != "/") | |
215 | Res += Dist; | |
216 | } | |
217 | else | |
218 | Res += Dist + '/' + Section; | |
219 | ||
220 | Res += " "; | |
221 | Res += Ver.ParentPkg().Name(); | |
222 | Res += " "; | |
dd13742e DK |
223 | if (Dist[Dist.size() - 1] != '/') |
224 | Res.append(Ver.Arch()).append(" "); | |
b2e465d6 AL |
225 | Res += Ver.VerStr(); |
226 | return Res; | |
227 | } | |
228 | /*}}}*/ | |
229 | // PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/ | |
230 | // --------------------------------------------------------------------- | |
231 | /* This should help the user find the index in the sources.list and | |
232 | in the filesystem for problem solving */ | |
af87ab54 | 233 | string debPackagesIndex::Describe(bool Short) const |
b2e465d6 AL |
234 | { |
235 | char S[300]; | |
af87ab54 AL |
236 | if (Short == true) |
237 | snprintf(S,sizeof(S),"%s",Info("Packages").c_str()); | |
238 | else | |
239 | snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(), | |
240 | IndexFile("Packages").c_str()); | |
b2e465d6 AL |
241 | return S; |
242 | } | |
243 | /*}}}*/ | |
244 | // PackagesIndex::Info - One liner describing the index URI /*{{{*/ | |
245 | // --------------------------------------------------------------------- | |
246 | /* */ | |
247 | string debPackagesIndex::Info(const char *Type) const | |
248 | { | |
5e02df82 | 249 | string Info = ::URI::NoUserPassword(URI) + ' '; |
b2e465d6 AL |
250 | if (Dist[Dist.size() - 1] == '/') |
251 | { | |
252 | if (Dist != "/") | |
253 | Info += Dist; | |
254 | } | |
255 | else | |
256 | Info += Dist + '/' + Section; | |
257 | Info += " "; | |
dd13742e DK |
258 | if (Dist[Dist.size() - 1] != '/') |
259 | Info += Architecture + " "; | |
b2e465d6 AL |
260 | Info += Type; |
261 | return Info; | |
262 | } | |
263 | /*}}}*/ | |
264 | // PackagesIndex::Index* - Return the URI to the index files /*{{{*/ | |
265 | // --------------------------------------------------------------------- | |
266 | /* */ | |
267 | inline string debPackagesIndex::IndexFile(const char *Type) const | |
268 | { | |
ec7a129e | 269 | string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); |
b0f4b486 MV |
270 | |
271 | std::vector<std::string> types = APT::Configuration::getCompressionTypes(); | |
272 | for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t) | |
273 | { | |
274 | string p = s + '.' + *t; | |
275 | if (FileExists(p)) | |
276 | return p; | |
277 | } | |
278 | return s; | |
b2e465d6 AL |
279 | } |
280 | string debPackagesIndex::IndexURI(const char *Type) const | |
281 | { | |
282 | string Res; | |
283 | if (Dist[Dist.size() - 1] == '/') | |
284 | { | |
285 | if (Dist != "/") | |
286 | Res = URI + Dist; | |
287 | else | |
288 | Res = URI; | |
289 | } | |
290 | else | |
291 | Res = URI + "dists/" + Dist + '/' + Section + | |
5dd4c8b8 | 292 | "/binary-" + Architecture + '/'; |
b2e465d6 AL |
293 | |
294 | Res += Type; | |
295 | return Res; | |
296 | } | |
297 | /*}}}*/ | |
b2e465d6 AL |
298 | // PackagesIndex::Exists - Check if the index is available /*{{{*/ |
299 | // --------------------------------------------------------------------- | |
300 | /* */ | |
301 | bool debPackagesIndex::Exists() const | |
302 | { | |
303 | return FileExists(IndexFile("Packages")); | |
304 | } | |
305 | /*}}}*/ | |
306 | // PackagesIndex::Size - Return the size of the index /*{{{*/ | |
307 | // --------------------------------------------------------------------- | |
308 | /* This is really only used for progress reporting. */ | |
309 | unsigned long debPackagesIndex::Size() const | |
310 | { | |
915f0520 MP |
311 | unsigned long size = 0; |
312 | ||
313 | /* we need to ignore errors here; if the lists are absent, just return 0 */ | |
314 | _error->PushToStack(); | |
315 | ||
f0e83599 | 316 | FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension); |
915f0520 MP |
317 | if (!f.Failed()) |
318 | size = f.Size(); | |
5473df3f | 319 | |
915f0520 MP |
320 | if (_error->PendingError() == true) |
321 | size = 0; | |
322 | _error->RevertToStack(); | |
323 | ||
324 | return size; | |
b2e465d6 AL |
325 | } |
326 | /*}}}*/ | |
327 | // PackagesIndex::Merge - Load the index file into a cache /*{{{*/ | |
328 | // --------------------------------------------------------------------- | |
329 | /* */ | |
2e5f4e45 | 330 | bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
b2e465d6 AL |
331 | { |
332 | string PackageFile = IndexFile("Packages"); | |
468720c5 | 333 | FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension); |
5dd4c8b8 | 334 | debListParser Parser(&Pkg, Architecture); |
3184b4cf | 335 | |
b2e465d6 AL |
336 | if (_error->PendingError() == true) |
337 | return _error->Error("Problem opening %s",PackageFile.c_str()); | |
2e5f4e45 DK |
338 | if (Prog != NULL) |
339 | Prog->SubProgress(0,Info("Packages")); | |
b2e465d6 AL |
340 | ::URI Tmp(URI); |
341 | if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false) | |
342 | return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); | |
343 | ||
344 | // Store the IMS information | |
345 | pkgCache::PkgFileIterator File = Gen.GetCurFile(); | |
a9fe5928 | 346 | pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File); |
76a763e1 DK |
347 | File->Size = Pkg.FileSize(); |
348 | File->mtime = Pkg.ModificationTime(); | |
b2e465d6 AL |
349 | |
350 | if (Gen.MergeList(Parser) == false) | |
351 | return _error->Error("Problem with MergeList %s",PackageFile.c_str()); | |
352 | ||
353 | // Check the release file | |
fe0f7911 DK |
354 | string ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("InRelease"); |
355 | bool releaseExists = false; | |
b2e465d6 | 356 | if (FileExists(ReleaseFile) == true) |
fe0f7911 DK |
357 | releaseExists = true; |
358 | else | |
359 | ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("Release"); | |
360 | ||
361 | if (releaseExists == true || FileExists(ReleaseFile) == true) | |
b2e465d6 | 362 | { |
233b7808 DK |
363 | FileFd Rel; |
364 | // Beware: The 'Release' file might be clearsigned in case the | |
365 | // signature for an 'InRelease' file couldn't be checked | |
366 | if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false) | |
367 | return false; | |
368 | ||
b2e465d6 AL |
369 | if (_error->PendingError() == true) |
370 | return false; | |
e011829d | 371 | Parser.LoadReleaseInfo(File,Rel,Section); |
b2e465d6 AL |
372 | } |
373 | ||
374 | return true; | |
375 | } | |
376 | /*}}}*/ | |
377 | // PackagesIndex::FindInCache - Find this index /*{{{*/ | |
378 | // --------------------------------------------------------------------- | |
379 | /* */ | |
380 | pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const | |
381 | { | |
382 | string FileName = IndexFile("Packages"); | |
383 | pkgCache::PkgFileIterator File = Cache.FileBegin(); | |
f7f0d6c7 | 384 | for (; File.end() == false; ++File) |
b2e465d6 | 385 | { |
f6442c77 | 386 | if (File.FileName() == NULL || FileName != File.FileName()) |
b2e465d6 AL |
387 | continue; |
388 | ||
389 | struct stat St; | |
390 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
391 | { |
392 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
393 | std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
b2e465d6 | 394 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 395 | } |
b2e465d6 | 396 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
397 | { |
398 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
399 | std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
400 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
401 | << ") doesn't match for " << File.FileName() << std::endl; | |
b2e465d6 | 402 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 403 | } |
b2e465d6 AL |
404 | return File; |
405 | } | |
406 | ||
407 | return File; | |
408 | } | |
409 | /*}}}*/ | |
410 | ||
a52f938b OS |
411 | // TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/ |
412 | // --------------------------------------------------------------------- | |
413 | /* */ | |
45df0ad2 DK |
414 | debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section, |
415 | char const * const Translation) : | |
416 | pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section), | |
417 | Language(Translation) | |
418 | {} | |
a52f938b OS |
419 | /*}}}*/ |
420 | // TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/ | |
421 | // --------------------------------------------------------------------- | |
422 | /* */ | |
423 | inline string debTranslationsIndex::IndexFile(const char *Type) const | |
424 | { | |
ec7a129e | 425 | string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); |
b0f4b486 MV |
426 | |
427 | std::vector<std::string> types = APT::Configuration::getCompressionTypes(); | |
428 | for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t) | |
429 | { | |
430 | string p = s + '.' + *t; | |
431 | if (FileExists(p)) | |
432 | return p; | |
433 | } | |
434 | return s; | |
a52f938b OS |
435 | } |
436 | string debTranslationsIndex::IndexURI(const char *Type) const | |
437 | { | |
438 | string Res; | |
439 | if (Dist[Dist.size() - 1] == '/') | |
440 | { | |
441 | if (Dist != "/") | |
422eeaaa | 442 | Res = URI + Dist; |
a52f938b | 443 | else |
422eeaaa | 444 | Res = URI; |
a52f938b OS |
445 | } |
446 | else | |
422eeaaa | 447 | Res = URI + "dists/" + Dist + '/' + Section + |
a52f938b OS |
448 | "/i18n/Translation-"; |
449 | ||
450 | Res += Type; | |
451 | return Res; | |
452 | } | |
453 | /*}}}*/ | |
454 | // TranslationsIndex::GetIndexes - Fetch the index files /*{{{*/ | |
455 | // --------------------------------------------------------------------- | |
456 | /* */ | |
457 | bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const | |
458 | { | |
e4d30d3f MV |
459 | string const TranslationFile = string("Translation-").append(Language); |
460 | new pkgAcqIndexTrans(Owner, IndexURI(Language), | |
461 | Info(TranslationFile.c_str()), | |
462 | TranslationFile); | |
a52f938b OS |
463 | |
464 | return true; | |
465 | } | |
466 | /*}}}*/ | |
467 | // TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/ | |
468 | // --------------------------------------------------------------------- | |
469 | /* This should help the user find the index in the sources.list and | |
470 | in the filesystem for problem solving */ | |
471 | string debTranslationsIndex::Describe(bool Short) const | |
472 | { | |
473 | char S[300]; | |
474 | if (Short == true) | |
475 | snprintf(S,sizeof(S),"%s",Info(TranslationFile().c_str()).c_str()); | |
476 | else | |
477 | snprintf(S,sizeof(S),"%s (%s)",Info(TranslationFile().c_str()).c_str(), | |
45df0ad2 | 478 | IndexFile(Language).c_str()); |
a52f938b OS |
479 | return S; |
480 | } | |
481 | /*}}}*/ | |
482 | // TranslationsIndex::Info - One liner describing the index URI /*{{{*/ | |
483 | // --------------------------------------------------------------------- | |
484 | /* */ | |
485 | string debTranslationsIndex::Info(const char *Type) const | |
486 | { | |
5e02df82 | 487 | string Info = ::URI::NoUserPassword(URI) + ' '; |
a52f938b OS |
488 | if (Dist[Dist.size() - 1] == '/') |
489 | { | |
490 | if (Dist != "/") | |
491 | Info += Dist; | |
492 | } | |
493 | else | |
494 | Info += Dist + '/' + Section; | |
495 | Info += " "; | |
496 | Info += Type; | |
497 | return Info; | |
498 | } | |
499 | /*}}}*/ | |
45df0ad2 | 500 | bool debTranslationsIndex::HasPackages() const /*{{{*/ |
11680bfd | 501 | { |
45df0ad2 | 502 | return FileExists(IndexFile(Language)); |
11680bfd | 503 | } |
45df0ad2 | 504 | /*}}}*/ |
a52f938b OS |
505 | // TranslationsIndex::Exists - Check if the index is available /*{{{*/ |
506 | // --------------------------------------------------------------------- | |
507 | /* */ | |
508 | bool debTranslationsIndex::Exists() const | |
509 | { | |
45df0ad2 | 510 | return FileExists(IndexFile(Language)); |
a52f938b OS |
511 | } |
512 | /*}}}*/ | |
513 | // TranslationsIndex::Size - Return the size of the index /*{{{*/ | |
514 | // --------------------------------------------------------------------- | |
515 | /* This is really only used for progress reporting. */ | |
516 | unsigned long debTranslationsIndex::Size() const | |
517 | { | |
915f0520 MP |
518 | unsigned long size = 0; |
519 | ||
520 | /* we need to ignore errors here; if the lists are absent, just return 0 */ | |
521 | _error->PushToStack(); | |
522 | ||
f0e83599 | 523 | FileFd f(IndexFile(Language), FileFd::ReadOnly, FileFd::Extension); |
915f0520 MP |
524 | if (!f.Failed()) |
525 | size = f.Size(); | |
5473df3f | 526 | |
915f0520 MP |
527 | if (_error->PendingError() == true) |
528 | size = 0; | |
529 | _error->RevertToStack(); | |
5473df3f | 530 | |
915f0520 | 531 | return size; |
a52f938b OS |
532 | } |
533 | /*}}}*/ | |
534 | // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ | |
535 | // --------------------------------------------------------------------- | |
536 | /* */ | |
2e5f4e45 | 537 | bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
a52f938b OS |
538 | { |
539 | // Check the translation file, if in use | |
45df0ad2 | 540 | string TranslationFile = IndexFile(Language); |
64c2bdc9 | 541 | if (FileExists(TranslationFile)) |
a52f938b | 542 | { |
468720c5 | 543 | FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension); |
bc1c9081 | 544 | debTranslationsParser TransParser(&Trans); |
a52f938b OS |
545 | if (_error->PendingError() == true) |
546 | return false; | |
547 | ||
2e5f4e45 DK |
548 | if (Prog != NULL) |
549 | Prog->SubProgress(0, Info(TranslationFile.c_str())); | |
a52f938b OS |
550 | if (Gen.SelectFile(TranslationFile,string(),*this) == false) |
551 | return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); | |
552 | ||
553 | // Store the IMS information | |
554 | pkgCache::PkgFileIterator TransFile = Gen.GetCurFile(); | |
76a763e1 DK |
555 | TransFile->Size = Trans.FileSize(); |
556 | TransFile->mtime = Trans.ModificationTime(); | |
a52f938b OS |
557 | |
558 | if (Gen.MergeList(TransParser) == false) | |
559 | return _error->Error("Problem with MergeList %s",TranslationFile.c_str()); | |
560 | } | |
561 | ||
562 | return true; | |
563 | } | |
564 | /*}}}*/ | |
c51c6f08 OS |
565 | // TranslationsIndex::FindInCache - Find this index /*{{{*/ |
566 | // --------------------------------------------------------------------- | |
567 | /* */ | |
568 | pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const | |
569 | { | |
45df0ad2 | 570 | string FileName = IndexFile(Language); |
4d34acf1 | 571 | |
c51c6f08 | 572 | pkgCache::PkgFileIterator File = Cache.FileBegin(); |
f7f0d6c7 | 573 | for (; File.end() == false; ++File) |
f416d22e MV |
574 | { |
575 | if (FileName != File.FileName()) | |
576 | continue; | |
4d34acf1 | 577 | |
f416d22e MV |
578 | struct stat St; |
579 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
580 | { |
581 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
582 | std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
f416d22e | 583 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 584 | } |
f416d22e | 585 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
586 | { |
587 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
588 | std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
589 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
590 | << ") doesn't match for " << File.FileName() << std::endl; | |
f416d22e | 591 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 592 | } |
f416d22e MV |
593 | return File; |
594 | } | |
c51c6f08 OS |
595 | return File; |
596 | } | |
597 | /*}}}*/ | |
b2e465d6 AL |
598 | // StatusIndex::debStatusIndex - Constructor /*{{{*/ |
599 | // --------------------------------------------------------------------- | |
600 | /* */ | |
7db98ffc | 601 | debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), File(File) |
b2e465d6 AL |
602 | { |
603 | } | |
604 | /*}}}*/ | |
605 | // StatusIndex::Size - Return the size of the index /*{{{*/ | |
606 | // --------------------------------------------------------------------- | |
607 | /* */ | |
608 | unsigned long debStatusIndex::Size() const | |
609 | { | |
610 | struct stat S; | |
611 | if (stat(File.c_str(),&S) != 0) | |
612 | return 0; | |
613 | return S.st_size; | |
614 | } | |
615 | /*}}}*/ | |
616 | // StatusIndex::Merge - Load the index file into a cache /*{{{*/ | |
617 | // --------------------------------------------------------------------- | |
618 | /* */ | |
2e5f4e45 | 619 | bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const |
b2e465d6 | 620 | { |
468720c5 | 621 | FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension); |
b2e465d6 AL |
622 | if (_error->PendingError() == true) |
623 | return false; | |
624 | debListParser Parser(&Pkg); | |
625 | if (_error->PendingError() == true) | |
626 | return false; | |
2e5f4e45 DK |
627 | |
628 | if (Prog != NULL) | |
629 | Prog->SubProgress(0,File); | |
b2e465d6 AL |
630 | if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false) |
631 | return _error->Error("Problem with SelectFile %s",File.c_str()); | |
632 | ||
633 | // Store the IMS information | |
634 | pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); | |
76a763e1 DK |
635 | CFile->Size = Pkg.FileSize(); |
636 | CFile->mtime = Pkg.ModificationTime(); | |
2b803d40 DK |
637 | map_ptrloc const storage = Gen.WriteUniqString("now"); |
638 | CFile->Archive = storage; | |
b2e465d6 AL |
639 | |
640 | if (Gen.MergeList(Parser) == false) | |
641 | return _error->Error("Problem with MergeList %s",File.c_str()); | |
642 | return true; | |
643 | } | |
644 | /*}}}*/ | |
645 | // StatusIndex::FindInCache - Find this index /*{{{*/ | |
646 | // --------------------------------------------------------------------- | |
647 | /* */ | |
648 | pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const | |
649 | { | |
650 | pkgCache::PkgFileIterator File = Cache.FileBegin(); | |
f7f0d6c7 | 651 | for (; File.end() == false; ++File) |
b2e465d6 AL |
652 | { |
653 | if (this->File != File.FileName()) | |
654 | continue; | |
655 | ||
656 | struct stat St; | |
657 | if (stat(File.FileName(),&St) != 0) | |
c8e572e3 MV |
658 | { |
659 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
660 | std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
b2e465d6 | 661 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 662 | } |
b2e465d6 | 663 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) |
c8e572e3 MV |
664 | { |
665 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
666 | std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
667 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
668 | << ") doesn't match for " << File.FileName() << std::endl; | |
b2e465d6 | 669 | return pkgCache::PkgFileIterator(Cache); |
c8e572e3 | 670 | } |
b2e465d6 AL |
671 | return File; |
672 | } | |
673 | return File; | |
674 | } | |
675 | /*}}}*/ | |
676 | // StatusIndex::Exists - Check if the index is available /*{{{*/ | |
677 | // --------------------------------------------------------------------- | |
678 | /* */ | |
a02db58f | 679 | APT_CONST bool debStatusIndex::Exists() const |
b2e465d6 AL |
680 | { |
681 | // Abort if the file does not exist. | |
682 | return true; | |
683 | } | |
684 | /*}}}*/ | |
685 | ||
b2e465d6 AL |
686 | // Index File types for Debian /*{{{*/ |
687 | class debIFTypeSrc : public pkgIndexFile::Type | |
688 | { | |
689 | public: | |
690 | ||
691 | debIFTypeSrc() {Label = "Debian Source Index";}; | |
692 | }; | |
693 | class debIFTypePkg : public pkgIndexFile::Type | |
694 | { | |
695 | public: | |
696 | ||
697 | virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const | |
698 | { | |
699 | return new debRecordParser(File.FileName(),*File.Cache()); | |
700 | }; | |
701 | debIFTypePkg() {Label = "Debian Package Index";}; | |
702 | }; | |
97234432 MV |
703 | class debIFTypeTrans : public debIFTypePkg |
704 | { | |
705 | public: | |
706 | debIFTypeTrans() {Label = "Debian Translation Index";}; | |
707 | }; | |
b2e465d6 AL |
708 | class debIFTypeStatus : public pkgIndexFile::Type |
709 | { | |
710 | public: | |
711 | ||
712 | virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const | |
713 | { | |
714 | return new debRecordParser(File.FileName(),*File.Cache()); | |
715 | }; | |
716 | debIFTypeStatus() {Label = "Debian dpkg status file";}; | |
717 | }; | |
718 | static debIFTypeSrc _apt_Src; | |
719 | static debIFTypePkg _apt_Pkg; | |
97234432 | 720 | static debIFTypeTrans _apt_Trans; |
b2e465d6 AL |
721 | static debIFTypeStatus _apt_Status; |
722 | ||
723 | const pkgIndexFile::Type *debSourcesIndex::GetType() const | |
724 | { | |
725 | return &_apt_Src; | |
726 | } | |
727 | const pkgIndexFile::Type *debPackagesIndex::GetType() const | |
728 | { | |
729 | return &_apt_Pkg; | |
730 | } | |
a52f938b OS |
731 | const pkgIndexFile::Type *debTranslationsIndex::GetType() const |
732 | { | |
97234432 | 733 | return &_apt_Trans; |
a52f938b | 734 | } |
b2e465d6 AL |
735 | const pkgIndexFile::Type *debStatusIndex::GetType() const |
736 | { | |
737 | return &_apt_Status; | |
738 | } | |
739 | ||
740 | /*}}}*/ |