]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debindexfile.cc
merged from lp:~donkult/apt/sid
[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";
69 if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip))
70 SourcesURI = SourcesURIgzip;
71
72 return new debSrcRecordParser(SourcesURI,this);
b2e465d6
AL
73}
74 /*}}}*/
75// SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/
76// ---------------------------------------------------------------------
77/* */
af87ab54 78string debSourcesIndex::Describe(bool Short) const
b2e465d6
AL
79{
80 char S[300];
af87ab54 81 if (Short == true)
cc742108 82 snprintf(S,sizeof(S),"%s",Info("Sources").c_str());
af87ab54 83 else
cc742108 84 snprintf(S,sizeof(S),"%s (%s)",Info("Sources").c_str(),
af87ab54
AL
85 IndexFile("Sources").c_str());
86
b2e465d6
AL
87 return S;
88}
89 /*}}}*/
90// SourcesIndex::Info - One liner describing the index URI /*{{{*/
91// ---------------------------------------------------------------------
92/* */
93string debSourcesIndex::Info(const char *Type) const
94{
5e02df82 95 string Info = ::URI::NoUserPassword(URI) + ' ';
b2e465d6
AL
96 if (Dist[Dist.size() - 1] == '/')
97 {
98 if (Dist != "/")
99 Info += Dist;
100 }
101 else
102 Info += Dist + '/' + Section;
103 Info += " ";
104 Info += Type;
105 return Info;
106}
107 /*}}}*/
108// SourcesIndex::Index* - Return the URI to the index files /*{{{*/
109// ---------------------------------------------------------------------
110/* */
111inline string debSourcesIndex::IndexFile(const char *Type) const
112{
ec7a129e 113 string s = URItoFileName(IndexURI(Type));
114 string sgzip = s + ".gz";
115 if (!FileExists(s) && FileExists(sgzip))
116 return sgzip;
117 else
118 return s;
b2e465d6 119}
ec7a129e 120
b2e465d6
AL
121string debSourcesIndex::IndexURI(const char *Type) const
122{
123 string Res;
124 if (Dist[Dist.size() - 1] == '/')
125 {
126 if (Dist != "/")
127 Res = URI + Dist;
128 else
129 Res = URI;
130 }
131 else
132 Res = URI + "dists/" + Dist + '/' + Section +
133 "/source/";
134
135 Res += Type;
136 return Res;
137}
138 /*}}}*/
b2e465d6
AL
139// SourcesIndex::Exists - Check if the index is available /*{{{*/
140// ---------------------------------------------------------------------
141/* */
142bool debSourcesIndex::Exists() const
143{
144 return FileExists(IndexFile("Sources"));
145}
146 /*}}}*/
147// SourcesIndex::Size - Return the size of the index /*{{{*/
148// ---------------------------------------------------------------------
149/* */
150unsigned long debSourcesIndex::Size() const
151{
915f0520
MP
152 unsigned long size = 0;
153
154 /* we need to ignore errors here; if the lists are absent, just return 0 */
155 _error->PushToStack();
156
5473df3f 157 FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnlyGzip);
915f0520
MP
158 if (!f.Failed())
159 size = f.Size();
160
161 if (_error->PendingError() == true)
162 size = 0;
163 _error->RevertToStack();
5473df3f 164
915f0520 165 return size;
b2e465d6
AL
166}
167 /*}}}*/
168
169// PackagesIndex::debPackagesIndex - Contructor /*{{{*/
170// ---------------------------------------------------------------------
171/* */
5dd4c8b8
DK
172debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section,
173 bool const &Trusted, string const &Arch) :
174 pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch)
b2e465d6 175{
5dd4c8b8
DK
176 if (Architecture == "native")
177 Architecture = _config->Find("APT::Architecture");
b2e465d6
AL
178}
179 /*}}}*/
180// PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/
181// ---------------------------------------------------------------------
182/* This is a shorter version that is designed to be < 60 chars or so */
183string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const
184{
5e02df82 185 string Res = ::URI::NoUserPassword(URI) + ' ';
b2e465d6
AL
186 if (Dist[Dist.size() - 1] == '/')
187 {
188 if (Dist != "/")
189 Res += Dist;
190 }
191 else
192 Res += Dist + '/' + Section;
193
194 Res += " ";
195 Res += Ver.ParentPkg().Name();
196 Res += " ";
dd13742e
DK
197 if (Dist[Dist.size() - 1] != '/')
198 Res.append(Ver.Arch()).append(" ");
b2e465d6
AL
199 Res += Ver.VerStr();
200 return Res;
201}
202 /*}}}*/
203// PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/
204// ---------------------------------------------------------------------
205/* This should help the user find the index in the sources.list and
206 in the filesystem for problem solving */
af87ab54 207string debPackagesIndex::Describe(bool Short) const
b2e465d6
AL
208{
209 char S[300];
af87ab54
AL
210 if (Short == true)
211 snprintf(S,sizeof(S),"%s",Info("Packages").c_str());
212 else
213 snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(),
214 IndexFile("Packages").c_str());
b2e465d6
AL
215 return S;
216}
217 /*}}}*/
218// PackagesIndex::Info - One liner describing the index URI /*{{{*/
219// ---------------------------------------------------------------------
220/* */
221string debPackagesIndex::Info(const char *Type) const
222{
5e02df82 223 string Info = ::URI::NoUserPassword(URI) + ' ';
b2e465d6
AL
224 if (Dist[Dist.size() - 1] == '/')
225 {
226 if (Dist != "/")
227 Info += Dist;
228 }
229 else
230 Info += Dist + '/' + Section;
231 Info += " ";
dd13742e
DK
232 if (Dist[Dist.size() - 1] != '/')
233 Info += Architecture + " ";
b2e465d6
AL
234 Info += Type;
235 return Info;
236}
237 /*}}}*/
238// PackagesIndex::Index* - Return the URI to the index files /*{{{*/
239// ---------------------------------------------------------------------
240/* */
241inline string debPackagesIndex::IndexFile(const char *Type) const
242{
ec7a129e 243 string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
244 string sgzip = s + ".gz";
245 if (!FileExists(s) && FileExists(sgzip))
246 return sgzip;
247 else
248 return s;
b2e465d6
AL
249}
250string debPackagesIndex::IndexURI(const char *Type) const
251{
252 string Res;
253 if (Dist[Dist.size() - 1] == '/')
254 {
255 if (Dist != "/")
256 Res = URI + Dist;
257 else
258 Res = URI;
259 }
260 else
261 Res = URI + "dists/" + Dist + '/' + Section +
5dd4c8b8 262 "/binary-" + Architecture + '/';
b2e465d6
AL
263
264 Res += Type;
265 return Res;
266}
267 /*}}}*/
b2e465d6
AL
268// PackagesIndex::Exists - Check if the index is available /*{{{*/
269// ---------------------------------------------------------------------
270/* */
271bool debPackagesIndex::Exists() const
272{
273 return FileExists(IndexFile("Packages"));
274}
275 /*}}}*/
276// PackagesIndex::Size - Return the size of the index /*{{{*/
277// ---------------------------------------------------------------------
278/* This is really only used for progress reporting. */
279unsigned long debPackagesIndex::Size() const
280{
915f0520
MP
281 unsigned long size = 0;
282
283 /* we need to ignore errors here; if the lists are absent, just return 0 */
284 _error->PushToStack();
285
5473df3f 286 FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnlyGzip);
915f0520
MP
287 if (!f.Failed())
288 size = f.Size();
5473df3f 289
915f0520
MP
290 if (_error->PendingError() == true)
291 size = 0;
292 _error->RevertToStack();
293
294 return size;
b2e465d6
AL
295}
296 /*}}}*/
297// PackagesIndex::Merge - Load the index file into a cache /*{{{*/
298// ---------------------------------------------------------------------
299/* */
2e5f4e45 300bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
b2e465d6
AL
301{
302 string PackageFile = IndexFile("Packages");
c4fc2fd7 303 FileFd Pkg(PackageFile,FileFd::ReadOnlyGzip);
5dd4c8b8 304 debListParser Parser(&Pkg, Architecture);
3184b4cf 305
b2e465d6
AL
306 if (_error->PendingError() == true)
307 return _error->Error("Problem opening %s",PackageFile.c_str());
2e5f4e45
DK
308 if (Prog != NULL)
309 Prog->SubProgress(0,Info("Packages"));
b2e465d6
AL
310 ::URI Tmp(URI);
311 if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false)
312 return _error->Error("Problem with SelectFile %s",PackageFile.c_str());
313
314 // Store the IMS information
315 pkgCache::PkgFileIterator File = Gen.GetCurFile();
a9fe5928 316 pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File);
b2e465d6
AL
317 struct stat St;
318 if (fstat(Pkg.Fd(),&St) != 0)
319 return _error->Errno("fstat","Failed to stat");
320 File->Size = St.st_size;
321 File->mtime = St.st_mtime;
322
323 if (Gen.MergeList(Parser) == false)
324 return _error->Error("Problem with MergeList %s",PackageFile.c_str());
325
326 // Check the release file
fe0f7911
DK
327 string ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("InRelease");
328 bool releaseExists = false;
b2e465d6 329 if (FileExists(ReleaseFile) == true)
fe0f7911
DK
330 releaseExists = true;
331 else
332 ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("Release");
333
334 if (releaseExists == true || FileExists(ReleaseFile) == true)
b2e465d6
AL
335 {
336 FileFd Rel(ReleaseFile,FileFd::ReadOnly);
337 if (_error->PendingError() == true)
338 return false;
e011829d 339 Parser.LoadReleaseInfo(File,Rel,Section);
b2e465d6
AL
340 }
341
342 return true;
343}
344 /*}}}*/
345// PackagesIndex::FindInCache - Find this index /*{{{*/
346// ---------------------------------------------------------------------
347/* */
348pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
349{
350 string FileName = IndexFile("Packages");
351 pkgCache::PkgFileIterator File = Cache.FileBegin();
352 for (; File.end() == false; File++)
353 {
f6442c77 354 if (File.FileName() == NULL || FileName != File.FileName())
b2e465d6
AL
355 continue;
356
357 struct stat St;
358 if (stat(File.FileName(),&St) != 0)
c8e572e3
MV
359 {
360 if (_config->FindB("Debug::pkgCacheGen", false))
361 std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
b2e465d6 362 return pkgCache::PkgFileIterator(Cache);
c8e572e3 363 }
b2e465d6 364 if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
c8e572e3
MV
365 {
366 if (_config->FindB("Debug::pkgCacheGen", false))
367 std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
368 << ") or mtime (" << St.st_mtime << " <> " << File->mtime
369 << ") doesn't match for " << File.FileName() << std::endl;
b2e465d6 370 return pkgCache::PkgFileIterator(Cache);
c8e572e3 371 }
b2e465d6
AL
372 return File;
373 }
374
375 return File;
376}
377 /*}}}*/
378
a52f938b
OS
379// TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/
380// ---------------------------------------------------------------------
381/* */
45df0ad2
DK
382debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section,
383 char const * const Translation) :
384 pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section),
385 Language(Translation)
386{}
a52f938b
OS
387 /*}}}*/
388// TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/
389// ---------------------------------------------------------------------
390/* */
391inline string debTranslationsIndex::IndexFile(const char *Type) const
392{
ec7a129e 393 string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
394 string sgzip = s + ".gz";
395 if (!FileExists(s) && FileExists(sgzip))
396 return sgzip;
397 else
398 return s;
a52f938b
OS
399}
400string debTranslationsIndex::IndexURI(const char *Type) const
401{
402 string Res;
403 if (Dist[Dist.size() - 1] == '/')
404 {
405 if (Dist != "/")
422eeaaa 406 Res = URI + Dist;
a52f938b 407 else
422eeaaa 408 Res = URI;
a52f938b
OS
409 }
410 else
422eeaaa 411 Res = URI + "dists/" + Dist + '/' + Section +
a52f938b
OS
412 "/i18n/Translation-";
413
414 Res += Type;
415 return Res;
416}
417 /*}}}*/
418// TranslationsIndex::GetIndexes - Fetch the index files /*{{{*/
419// ---------------------------------------------------------------------
420/* */
421bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const
422{
770c32ec 423 if (TranslationsAvailable()) {
45df0ad2
DK
424 string const TranslationFile = string("Translation-").append(Language);
425 new pkgAcqIndexTrans(Owner, IndexURI(Language),
a52f938b
OS
426 Info(TranslationFile.c_str()),
427 TranslationFile);
428 }
429
430 return true;
431}
432 /*}}}*/
433// TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/
434// ---------------------------------------------------------------------
435/* This should help the user find the index in the sources.list and
436 in the filesystem for problem solving */
437string debTranslationsIndex::Describe(bool Short) const
438{
439 char S[300];
440 if (Short == true)
441 snprintf(S,sizeof(S),"%s",Info(TranslationFile().c_str()).c_str());
442 else
443 snprintf(S,sizeof(S),"%s (%s)",Info(TranslationFile().c_str()).c_str(),
45df0ad2 444 IndexFile(Language).c_str());
a52f938b
OS
445 return S;
446}
447 /*}}}*/
448// TranslationsIndex::Info - One liner describing the index URI /*{{{*/
449// ---------------------------------------------------------------------
450/* */
451string debTranslationsIndex::Info(const char *Type) const
452{
5e02df82 453 string Info = ::URI::NoUserPassword(URI) + ' ';
a52f938b
OS
454 if (Dist[Dist.size() - 1] == '/')
455 {
456 if (Dist != "/")
457 Info += Dist;
458 }
459 else
460 Info += Dist + '/' + Section;
461 Info += " ";
462 Info += Type;
463 return Info;
464}
465 /*}}}*/
45df0ad2 466bool debTranslationsIndex::HasPackages() const /*{{{*/
11680bfd 467{
770c32ec 468 if(!TranslationsAvailable())
11680bfd
MV
469 return false;
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);
770c32ec 510 if (TranslationsAvailable() && 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();
f416d22e
MV
545 for (; File.end() == false; File++)
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();
625 for (; File.end() == false; File++)
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 /*}}}*/