]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgrecords.cc
testcases runable as root
[apt.git] / apt-pkg / pkgrecords.cc
CommitLineData
f55ece0e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
f50d1cfa 3// $Id: pkgrecords.cc,v 1.8 2003/09/02 04:52:16 mdz Exp $
f55ece0e
AL
4/* ######################################################################
5
6 Package Records - Allows access to complete package description records
7 directly from the file.
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
ea542140
DK
12#include<config.h>
13
f55ece0e 14#include <apt-pkg/pkgrecords.h>
b2e465d6 15#include <apt-pkg/indexfile.h>
f55ece0e 16#include <apt-pkg/error.h>
453b82a3
DK
17#include <apt-pkg/pkgcache.h>
18#include <apt-pkg/cacheiterators.h>
19
20#include <stddef.h>
21#include <vector>
ea542140
DK
22
23#include <apti18n.h>
f55ece0e
AL
24 /*}}}*/
25
26// Records::pkgRecords - Constructor /*{{{*/
27// ---------------------------------------------------------------------
28/* This will create the necessary structures to access the status files */
80624be7 29pkgRecords::pkgRecords(pkgCache &aCache) : d(NULL), Cache(aCache),
30257943 30 Files(Cache.HeaderP->PackageFileCount)
f55ece0e 31{
30257943 32 for (pkgCache::PkgFileIterator I = Cache.FileBegin();
f7f0d6c7 33 I.end() == false; ++I)
f55ece0e 34 {
b2e465d6
AL
35 const pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(I.IndexType());
36 if (Type == 0)
3164dff9 37 {
30257943
MV
38 _error->Error(_("Index file type '%s' is not supported"),I.IndexType());
39 return;
3164dff9 40 }
b2e465d6
AL
41
42 Files[I->ID] = Type->CreatePkgParser(I);
43 if (Files[I->ID] == 0)
30257943
MV
44 return;
45 }
f55ece0e
AL
46}
47 /*}}}*/
48// Records::~pkgRecords - Destructor /*{{{*/
49// ---------------------------------------------------------------------
50/* */
51pkgRecords::~pkgRecords()
52{
8f3ba4e8 53 for ( std::vector<Parser*>::iterator it = Files.begin();
30257943
MV
54 it != Files.end();
55 ++it)
56 {
57 delete *it;
58 }
f55ece0e
AL
59}
60 /*}}}*/
61// Records::Lookup - Get a parser for the package version file /*{{{*/
62// ---------------------------------------------------------------------
63/* */
03e39e59
AL
64pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
65{
b2e465d6
AL
66 Files[Ver.File()->ID]->Jump(Ver);
67 return *Files[Ver.File()->ID];
f55ece0e
AL
68}
69 /*}}}*/
a52f938b
OS
70// Records::Lookup - Get a parser for the package description file /*{{{*/
71// ---------------------------------------------------------------------
72/* */
73pkgRecords::Parser &pkgRecords::Lookup(pkgCache::DescFileIterator const &Desc)
74{
75 Files[Desc.File()->ID]->Jump(Desc);
76 return *Files[Desc.File()->ID];
77}
78 /*}}}*/