]> git.saurik.com Git - apt.git/blame - apt-pkg/srcrecords.cc
Merge remote-tracking branch 'mvo/bugfix/apt-get-source-unauthenticated-warning'...
[apt.git] / apt-pkg / srcrecords.cc
CommitLineData
11e7af84
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b3d44315 3// $Id: srcrecords.cc,v 1.7.2.2 2003/12/26 16:27:34 mdz Exp $
11e7af84
AL
4/* ######################################################################
5
6 Source Package Records - Allows access to source package records
7
8 Parses and allows access to the list of source records and searching by
9 source name on that list.
10
11 ##################################################################### */
12 /*}}}*/
13// Include Files /*{{{*/
ea542140
DK
14#include<config.h>
15
11e7af84
AL
16#include <apt-pkg/srcrecords.h>
17#include <apt-pkg/error.h>
b2e465d6 18#include <apt-pkg/sourcelist.h>
472ff00e 19#include <apt-pkg/metaindex.h>
453b82a3
DK
20#include <apt-pkg/indexfile.h>
21#include <apt-pkg/macros.h>
22
23#include <string.h>
24#include <string>
25#include <vector>
ea542140
DK
26
27#include <apti18n.h>
11e7af84
AL
28 /*}}}*/
29
30// SrcRecords::pkgSrcRecords - Constructor /*{{{*/
31// ---------------------------------------------------------------------
32/* Open all the source index files */
dcaa1185 33pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : d(NULL), Files(0), Current(0)
11e7af84 34{
f7f0d6c7 35 for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); ++I)
b2e465d6 36 {
73688d27
DK
37 std::vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
38 for (std::vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
f7f0d6c7 39 J != Indexes->end(); ++J)
b3d44315
MV
40 {
41 Parser* P = (*J)->CreateSrcParser();
42 if (_error->PendingError() == true)
43 return;
44 if (P != 0)
45 Files.push_back(P);
46 }
b2e465d6 47 }
b2e465d6 48
0e72dd52 49 // Doesn't work without any source index files
69c2ecbd 50 if (Files.empty() == true)
11e7af84 51 {
677cbcbc 52 _error->Error(_("You must put some 'source' URIs"
b2e465d6 53 " in your sources.list"));
11e7af84
AL
54 return;
55 }
56
11e7af84
AL
57 Restart();
58}
59 /*}}}*/
60// SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
61// ---------------------------------------------------------------------
62/* */
63pkgSrcRecords::~pkgSrcRecords()
64{
11e7af84 65 // Blow away all the parser objects
73688d27 66 for(std::vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
b3d44315 67 delete *I;
11e7af84
AL
68}
69 /*}}}*/
70// SrcRecords::Restart - Restart the search /*{{{*/
71// ---------------------------------------------------------------------
72/* Return all of the parsers to their starting position */
73bool pkgSrcRecords::Restart()
74{
b3d44315 75 Current = Files.begin();
73688d27 76 for (std::vector<Parser*>::iterator I = Files.begin();
f7f0d6c7 77 I != Files.end(); ++I)
6a9c9d63
DK
78 if ((*I)->Offset() != 0)
79 (*I)->Restart();
80
11e7af84
AL
81 return true;
82}
83 /*}}}*/
46255701
MV
84// SrcRecords::Next - Step to the next Source Record /*{{{*/
85// ---------------------------------------------------------------------
86/* Step to the next source package record */
87const pkgSrcRecords::Parser* pkgSrcRecords::Next()
88{
89 if (Current == Files.end())
90 return 0;
91
92 // Step to the next record, possibly switching files
93 while ((*Current)->Step() == false)
94 {
95 if (_error->PendingError() == true)
96 return 0;
97 ++Current;
98 if (Current == Files.end())
99 return 0;
100 }
101
102 return *Current;
103}
104 /*}}}*/
11e7af84
AL
105// SrcRecords::Find - Find the first source package with the given name /*{{{*/
106// ---------------------------------------------------------------------
107/* This searches on both source package names and output binary names and
108 returns the first found. A 'cursor' like system is used to allow this
109 function to be called multiple times to get successive entries */
41c81fd8 110pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOnly)
11e7af84 111{
11e7af84
AL
112 while (true)
113 {
46255701
MV
114 if(Next() == 0)
115 return 0;
116
11e7af84
AL
117 // IO error somehow
118 if (_error->PendingError() == true)
119 return 0;
120
121 // Source name hit
122 if ((*Current)->Package() == Package)
123 return *Current;
124
125 if (SrcOnly == true)
126 continue;
127
128 // Check for a binary hit
129 const char **I = (*Current)->Binaries();
f7f0d6c7 130 for (; I != 0 && *I != 0; ++I)
11e7af84
AL
131 if (strcmp(Package,*I) == 0)
132 return *Current;
133 }
134}
135 /*}}}*/
b2e465d6
AL
136// Parser::BuildDepType - Convert a build dep to a string /*{{{*/
137// ---------------------------------------------------------------------
138/* */
41c81fd8 139const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type)
b2e465d6 140{
69c2ecbd
DK
141 const char *fields[] = {"Build-Depends",
142 "Build-Depends-Indep",
b2e465d6
AL
143 "Build-Conflicts",
144 "Build-Conflicts-Indep"};
69c2ecbd 145 if (unlikely(Type >= sizeof(fields)/sizeof(fields[0])))
b2e465d6 146 return "";
69c2ecbd 147 return fields[Type];
b2e465d6
AL
148}
149 /*}}}*/
150
11e7af84 151