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