]>
git.saurik.com Git - apt.git/blob - apt-pkg/srcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: srcrecords.cc,v 1.7.2.2 2003/12/26 16:27:34 mdz Exp $
4 /* ######################################################################
6 Source Package Records - Allows access to source package records
8 Parses and allows access to the list of source records and searching by
9 source name on that list.
11 ##################################################################### */
13 // Include Files /*{{{*/
16 #include <apt-pkg/srcrecords.h>
17 #include <apt-pkg/debsrcrecords.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/sourcelist.h>
20 #include <apt-pkg/metaindex.h>
21 #include <apt-pkg/indexfile.h>
22 #include <apt-pkg/macros.h>
31 // SrcRecords::pkgSrcRecords - Constructor /*{{{*/
32 // ---------------------------------------------------------------------
33 /* Open all the source index files */
34 pkgSrcRecords::pkgSrcRecords(pkgSourceList
&List
) : d(NULL
), Files(0)
36 for (pkgSourceList::const_iterator I
= List
.begin(); I
!= List
.end(); ++I
)
38 std::vector
<pkgIndexFile
*> *Indexes
= (*I
)->GetIndexFiles();
39 for (std::vector
<pkgIndexFile
*>::const_iterator J
= Indexes
->begin();
40 J
!= Indexes
->end(); ++J
)
42 _error
->PushToStack();
43 Parser
* P
= (*J
)->CreateSrcParser();
44 bool const newError
= _error
->PendingError();
45 _error
->MergeWithStack();
53 // Doesn't work without any source index files
54 if (Files
.empty() == true)
56 _error
->Error(_("You must put some 'source' URIs"
57 " in your sources.list"));
64 // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
65 // ---------------------------------------------------------------------
67 pkgSrcRecords::~pkgSrcRecords()
69 // Blow away all the parser objects
70 for(std::vector
<Parser
*>::iterator I
= Files
.begin(); I
!= Files
.end(); ++I
)
74 // SrcRecords::Restart - Restart the search /*{{{*/
75 // ---------------------------------------------------------------------
76 /* Return all of the parsers to their starting position */
77 bool pkgSrcRecords::Restart()
79 Current
= Files
.begin();
80 for (std::vector
<Parser
*>::iterator I
= Files
.begin();
81 I
!= Files
.end(); ++I
)
82 if ((*I
)->Offset() != 0)
88 // SrcRecords::Step - Step to the next Source Record /*{{{*/
89 // ---------------------------------------------------------------------
90 /* Step to the next source package record */
91 const pkgSrcRecords::Parser
* pkgSrcRecords::Step()
93 if (Current
== Files
.end())
96 // Step to the next record, possibly switching files
97 while ((*Current
)->Step() == false)
100 if (Current
== Files
.end())
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 */
112 pkgSrcRecords::Parser
*pkgSrcRecords::Find(const char *Package
,bool const &SrcOnly
)
120 if ((*Current
)->Package() == Package
)
126 // Check for a binary hit
127 const char **I
= (*Current
)->Binaries();
128 for (; I
!= 0 && *I
!= 0; ++I
)
129 if (strcmp(Package
,*I
) == 0)
134 // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
135 // ---------------------------------------------------------------------
137 const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type
)
139 const char *fields
[] = {"Build-Depends",
140 "Build-Depends-Indep",
142 "Build-Conflicts-Indep",
143 "Build-Depends-Arch",
144 "Build-Conflicts-Arch"};
145 if (unlikely(Type
>= sizeof(fields
)/sizeof(fields
[0])))
150 bool pkgSrcRecords::Parser::Files2(std::vector
<pkgSrcRecords::File2
> &F2
)/*{{{*/
152 debSrcRecordParser
* const deb
= dynamic_cast<debSrcRecordParser
*>(this);
154 return deb
->Files2(F2
);
156 std::vector
<pkgSrcRecords::File
> F
;
157 if (Files(F
) == false)
159 for (std::vector
<pkgSrcRecords::File
>::const_iterator f
= F
.begin(); f
!= F
.end(); ++f
)
161 pkgSrcRecords::File2 f2
;
163 #pragma GCC diagnostic push
164 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
166 f2
.MD5Hash
= f
->MD5Hash
;
168 f2
.Hashes
.push_back(HashString("MD5Sum", f
->MD5Hash
));
169 f2
.FileSize
= f
->Size
;
171 #pragma GCC diagnostic pop
182 pkgSrcRecords::Parser::Parser(const pkgIndexFile
*Index
) : d(NULL
), iIndex(Index
) {}
183 pkgSrcRecords::Parser::~Parser() {}