]>
git.saurik.com Git - apt.git/blob - apt-pkg/versionmatch.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: versionmatch.cc,v 1.9 2003/05/19 17:58:26 doogie Exp $
4 /* ######################################################################
8 This module takes a matching string and a type and locates the version
9 record that satisfies the constraint described by the matching string.
11 ##################################################################### */
13 // Include Files /*{{{*/
14 #include <apt-pkg/versionmatch.h>
16 #include <apt-pkg/strutl.h>
17 #include <apt-pkg/error.h>
23 // VersionMatch::pkgVersionMatch - Constructor /*{{{*/
24 // ---------------------------------------------------------------------
25 /* Break up the data string according to the selected type */
26 pkgVersionMatch::pkgVersionMatch(string Data
,MatchType Type
) : Type(Type
)
29 VerPrefixMatch
= false;
30 RelVerPrefixMatch
= false;
32 if (Type
== None
|| Data
.length() < 1)
35 // Cut up the version representation
38 if (Data
.end()[-1] == '*')
40 VerPrefixMatch
= true;
41 VerStr
= string(Data
,0,Data
.length()-1);
50 // All empty = match all
57 // Are we a simple specification?
58 string::const_iterator I
= Data
.begin();
59 for (; I
!= Data
.end() && *I
!= '='; I
++);
68 if (RelVerStr
.length() > 0 && RelVerStr
.end()[-1] == '*')
70 RelVerPrefixMatch
= true;
71 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
78 snprintf(Spec
,sizeof(Spec
),"%s",Data
.c_str());
79 if (TokSplitString(',',Spec
,Fragments
,
80 sizeof(Fragments
)/sizeof(Fragments
[0])) == false)
86 for (unsigned J
= 0; Fragments
[J
] != 0; J
++)
88 if (strlen(Fragments
[J
]) < 3)
91 if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"v=") == 0)
92 RelVerStr
= Fragments
[J
]+2;
93 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"o=") == 0)
94 RelOrigin
= Fragments
[J
]+2;
95 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"a=") == 0)
96 RelArchive
= Fragments
[J
]+2;
97 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"n=") == 0)
98 RelCodename
= Fragments
[J
]+2;
99 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"l=") == 0)
100 RelLabel
= Fragments
[J
]+2;
101 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"c=") == 0)
102 RelComponent
= Fragments
[J
]+2;
105 if (RelVerStr
.end()[-1] == '*')
107 RelVerPrefixMatch
= true;
108 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
120 // VersionMatch::MatchVer - Match a version string with prefixing /*{{{*/
121 // ---------------------------------------------------------------------
123 bool pkgVersionMatch::MatchVer(const char *A
,string B
,bool Prefix
)
126 const char *Ae
= Ab
+ strlen(A
);
128 // Strings are not a compatible size.
129 if (((unsigned)(Ae
- Ab
) != B
.length() && Prefix
== false) ||
130 (unsigned)(Ae
- Ab
) < B
.length())
134 if (stringcasecmp(B
,Ab
,Ab
+ B
.length()) == 0)
140 // VersionMatch::Find - Locate the best match for the select type /*{{{*/
141 // ---------------------------------------------------------------------
143 pkgCache::VerIterator
pkgVersionMatch::Find(pkgCache::PkgIterator Pkg
)
145 pkgCache::VerIterator Ver
= Pkg
.VersionList();
146 for (; Ver
.end() == false; Ver
++)
150 if (MatchVer(Ver
.VerStr(),VerStr
,VerPrefixMatch
) == true)
155 for (pkgCache::VerFileIterator VF
= Ver
.FileList(); VF
.end() == false; VF
++)
156 if (FileMatch(VF
.File()) == true)
160 // This will be Ended by now.
164 // VersionMatch::FileMatch - Match against an index file /*{{{*/
165 // ---------------------------------------------------------------------
166 /* This matcher checks against the release file and the origin location
167 to see if the constraints are met. */
168 bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File
)
172 if (MatchAll
== true)
175 /* cout << RelVerStr << ',' << RelOrigin << ',' << RelArchive << ',' << RelLabel << endl;
176 cout << File.Version() << ',' << File.Origin() << ',' << File.Archive() << ',' << File.Label() << endl;*/
178 if (RelVerStr
.empty() == true && RelOrigin
.empty() == true &&
179 RelArchive
.empty() == true && RelLabel
.empty() == true &&
180 RelRelease
.empty() == true && RelCodename
.empty() == true &&
181 RelComponent
.empty() == true)
184 if (RelVerStr
.empty() == false)
185 if (File
->Version
== 0 ||
186 MatchVer(File
.Version(),RelVerStr
,RelVerPrefixMatch
) == false)
188 if (RelOrigin
.empty() == false)
189 if (File
->Origin
== 0 ||
190 stringcasecmp(RelOrigin
,File
.Origin()) != 0)
192 if (RelArchive
.empty() == false)
193 if (File
->Archive
== 0 ||
194 stringcasecmp(RelArchive
,File
.Archive()) != 0)
196 if (RelCodename
.empty() == false)
197 if (File
->Codename
== 0 ||
198 stringcasecmp(RelCodename
,File
.Codename()) != 0)
200 if (RelRelease
.empty() == false)
201 if ((File
->Archive
== 0 ||
202 stringcasecmp(RelRelease
,File
.Archive()) != 0) &&
203 (File
->Codename
== 0 ||
204 stringcasecmp(RelRelease
,File
.Codename()) != 0))
206 if (RelLabel
.empty() == false)
207 if (File
->Label
== 0 ||
208 stringcasecmp(RelLabel
,File
.Label()) != 0)
210 if (RelComponent
.empty() == false)
211 if (File
->Component
== 0 ||
212 stringcasecmp(RelComponent
,File
.Component()) != 0)
219 if (OrSite
.empty() == false) {
220 if (File
->Site
== 0 || OrSite
!= File
.Site())
222 } else // so we are talking about file:// or status file
223 if (strcmp(File
.Site(),"") == 0 && File
->Archive
!= 0) // skip the status file
225 return (OrSite
== File
.Site()); /* both strings match */