]> git.saurik.com Git - apt.git/blame - apt-pkg/srcrecords.cc
travis: Add coverage testing using codecov.io
[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 16#include <apt-pkg/srcrecords.h>
3a2b39ee 17#include <apt-pkg/debsrcrecords.h>
11e7af84 18#include <apt-pkg/error.h>
b2e465d6 19#include <apt-pkg/sourcelist.h>
472ff00e 20#include <apt-pkg/metaindex.h>
453b82a3
DK
21#include <apt-pkg/indexfile.h>
22#include <apt-pkg/macros.h>
23
24#include <string.h>
25#include <string>
26#include <vector>
ea542140
DK
27
28#include <apti18n.h>
11e7af84
AL
29 /*}}}*/
30
31// SrcRecords::pkgSrcRecords - Constructor /*{{{*/
32// ---------------------------------------------------------------------
33/* Open all the source index files */
f8043f21 34pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : d(NULL), Files(0)
11e7af84 35{
f7f0d6c7 36 for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); ++I)
b2e465d6 37 {
73688d27
DK
38 std::vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
39 for (std::vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
f7f0d6c7 40 J != Indexes->end(); ++J)
b3d44315 41 {
95278287
DK
42 _error->PushToStack();
43 Parser* P = (*J)->CreateSrcParser();
44 bool const newError = _error->PendingError();
45 _error->MergeWithStack();
46 if (newError)
47 return;
48 if (P != 0)
49 Files.push_back(P);
b3d44315 50 }
b2e465d6 51 }
b2e465d6 52
0e72dd52 53 // Doesn't work without any source index files
69c2ecbd 54 if (Files.empty() == true)
11e7af84 55 {
677cbcbc 56 _error->Error(_("You must put some 'source' URIs"
b2e465d6 57 " in your sources.list"));
11e7af84
AL
58 return;
59 }
60
11e7af84
AL
61 Restart();
62}
63 /*}}}*/
64// SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
65// ---------------------------------------------------------------------
66/* */
67pkgSrcRecords::~pkgSrcRecords()
68{
11e7af84 69 // Blow away all the parser objects
73688d27 70 for(std::vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
b3d44315 71 delete *I;
11e7af84
AL
72}
73 /*}}}*/
74// SrcRecords::Restart - Restart the search /*{{{*/
75// ---------------------------------------------------------------------
76/* Return all of the parsers to their starting position */
77bool pkgSrcRecords::Restart()
78{
b3d44315 79 Current = Files.begin();
73688d27 80 for (std::vector<Parser*>::iterator I = Files.begin();
f7f0d6c7 81 I != Files.end(); ++I)
6a9c9d63
DK
82 if ((*I)->Offset() != 0)
83 (*I)->Restart();
84
11e7af84
AL
85 return true;
86}
87 /*}}}*/
401e5db1 88// SrcRecords::Step - Step to the next Source Record /*{{{*/
46255701
MV
89// ---------------------------------------------------------------------
90/* Step to the next source package record */
401e5db1 91const pkgSrcRecords::Parser* pkgSrcRecords::Step()
46255701
MV
92{
93 if (Current == Files.end())
94 return 0;
95
96 // Step to the next record, possibly switching files
97 while ((*Current)->Step() == false)
98 {
46255701
MV
99 ++Current;
100 if (Current == Files.end())
101 return 0;
102 }
103
104 return *Current;
105}
106 /*}}}*/
11e7af84
AL
107// SrcRecords::Find - Find the first source package with the given name /*{{{*/
108// ---------------------------------------------------------------------
109/* This searches on both source package names and output binary names and
110 returns the first found. A 'cursor' like system is used to allow this
111 function to be called multiple times to get successive entries */
41c81fd8 112pkgSrcRecords::Parser *pkgSrcRecords::Find(const char *Package,bool const &SrcOnly)
11e7af84 113{
11e7af84
AL
114 while (true)
115 {
401e5db1 116 if(Step() == 0)
46255701
MV
117 return 0;
118
11e7af84
AL
119 // Source name hit
120 if ((*Current)->Package() == Package)
121 return *Current;
122
123 if (SrcOnly == true)
124 continue;
125
126 // Check for a binary hit
127 const char **I = (*Current)->Binaries();
f7f0d6c7 128 for (; I != 0 && *I != 0; ++I)
11e7af84
AL
129 if (strcmp(Package,*I) == 0)
130 return *Current;
131 }
132}
133 /*}}}*/
b2e465d6
AL
134// Parser::BuildDepType - Convert a build dep to a string /*{{{*/
135// ---------------------------------------------------------------------
136/* */
41c81fd8 137const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type)
b2e465d6 138{
69c2ecbd
DK
139 const char *fields[] = {"Build-Depends",
140 "Build-Depends-Indep",
b2e465d6
AL
141 "Build-Conflicts",
142 "Build-Conflicts-Indep"};
69c2ecbd 143 if (unlikely(Type >= sizeof(fields)/sizeof(fields[0])))
b2e465d6 144 return "";
69c2ecbd 145 return fields[Type];
b2e465d6
AL
146}
147 /*}}}*/
3a2b39ee
DK
148bool pkgSrcRecords::Parser::Files2(std::vector<pkgSrcRecords::File2> &F2)/*{{{*/
149{
150 debSrcRecordParser * const deb = dynamic_cast<debSrcRecordParser*>(this);
151 if (deb != NULL)
152 return deb->Files2(F2);
b2e465d6 153
3a2b39ee
DK
154 std::vector<pkgSrcRecords::File> F;
155 if (Files(F) == false)
156 return false;
157 for (std::vector<pkgSrcRecords::File>::const_iterator f = F.begin(); f != F.end(); ++f)
158 {
159 pkgSrcRecords::File2 f2;
160#if __GNUC__ >= 4
161 #pragma GCC diagnostic push
162 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
163#endif
164 f2.MD5Hash = f->MD5Hash;
165 f2.Size = f->Size;
166 f2.Hashes.push_back(HashString("MD5Sum", f->MD5Hash));
167 f2.FileSize = f->Size;
168#if __GNUC__ >= 4
169 #pragma GCC diagnostic pop
170#endif
171 f2.Path = f->Path;
172 f2.Type = f->Type;
173 F2.push_back(f2);
174 }
175 return true;
176}
177 /*}}}*/
e8afd168
DK
178
179
6c55f07a 180pkgSrcRecords::Parser::Parser(const pkgIndexFile *Index) : d(NULL), iIndex(Index) {}
e8afd168 181pkgSrcRecords::Parser::~Parser() {}