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