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