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