]>
git.saurik.com Git - apt.git/blob - apt-pkg/srcrecords.cc
3175ee75f5145bd3d7a829f6be2d36f05952fea0
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), Current(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 Parser
* P
= (*J
)->CreateSrcParser();
43 if (_error
->PendingError() == true)
50 // Doesn't work without any source index files
51 if (Files
.empty() == true)
53 _error
->Error(_("You must put some 'source' URIs"
54 " in your sources.list"));
61 // SrcRecords::~pkgSrcRecords - Destructor /*{{{*/
62 // ---------------------------------------------------------------------
64 pkgSrcRecords::~pkgSrcRecords()
66 // Blow away all the parser objects
67 for(std::vector
<Parser
*>::iterator I
= Files
.begin(); I
!= Files
.end(); ++I
)
71 // SrcRecords::Restart - Restart the search /*{{{*/
72 // ---------------------------------------------------------------------
73 /* Return all of the parsers to their starting position */
74 bool pkgSrcRecords::Restart()
76 Current
= Files
.begin();
77 for (std::vector
<Parser
*>::iterator I
= Files
.begin();
78 I
!= Files
.end(); ++I
)
79 if ((*I
)->Offset() != 0)
85 // SrcRecords::Step - Step to the next Source Record /*{{{*/
86 // ---------------------------------------------------------------------
87 /* Step to the next source package record */
88 const pkgSrcRecords::Parser
* pkgSrcRecords::Step()
90 if (Current
== Files
.end())
93 // Step to the next record, possibly switching files
94 while ((*Current
)->Step() == false)
96 if (_error
->PendingError() == true)
99 if (Current
== Files
.end())
106 // SrcRecords::Find - Find the first source package with the given name /*{{{*/
107 // ---------------------------------------------------------------------
108 /* This searches on both source package names and output binary names and
109 returns the first found. A 'cursor' like system is used to allow this
110 function to be called multiple times to get successive entries */
111 pkgSrcRecords::Parser
*pkgSrcRecords::Find(const char *Package
,bool const &SrcOnly
)
119 if (_error
->PendingError() == true)
123 if ((*Current
)->Package() == Package
)
129 // Check for a binary hit
130 const char **I
= (*Current
)->Binaries();
131 for (; I
!= 0 && *I
!= 0; ++I
)
132 if (strcmp(Package
,*I
) == 0)
137 // Parser::BuildDepType - Convert a build dep to a string /*{{{*/
138 // ---------------------------------------------------------------------
140 const char *pkgSrcRecords::Parser::BuildDepType(unsigned char const &Type
)
142 const char *fields
[] = {"Build-Depends",
143 "Build-Depends-Indep",
145 "Build-Conflicts-Indep"};
146 if (unlikely(Type
>= sizeof(fields
)/sizeof(fields
[0])))
151 bool pkgSrcRecords::Parser::Files2(std::vector
<pkgSrcRecords::File2
> &F2
)/*{{{*/
153 debSrcRecordParser
* const deb
= dynamic_cast<debSrcRecordParser
*>(this);
155 return deb
->Files2(F2
);
157 std::vector
<pkgSrcRecords::File
> F
;
158 if (Files(F
) == false)
160 for (std::vector
<pkgSrcRecords::File
>::const_iterator f
= F
.begin(); f
!= F
.end(); ++f
)
162 pkgSrcRecords::File2 f2
;
164 #pragma GCC diagnostic push
165 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
167 f2
.MD5Hash
= f
->MD5Hash
;
169 f2
.Hashes
.push_back(HashString("MD5Sum", f
->MD5Hash
));
170 f2
.FileSize
= f
->Size
;
172 #pragma GCC diagnostic pop