]>
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 /*{{{*/
15 #pragma implementation "apt-pkg/versionmatch.h"
17 #include <apt-pkg/versionmatch.h>
19 #include <apt-pkg/strutl.h>
20 #include <apt-pkg/error.h>
26 // VersionMatch::pkgVersionMatch - Constructor /*{{{*/
27 // ---------------------------------------------------------------------
28 /* Break up the data string according to the selected type */
29 pkgVersionMatch::pkgVersionMatch(string Data
,MatchType Type
) : Type(Type
)
32 VerPrefixMatch
= false;
33 RelVerPrefixMatch
= false;
35 if (Type
== None
|| Data
.length() < 1)
38 // Cut up the version representation
41 if (Data
.end()[-1] == '*')
43 VerPrefixMatch
= true;
44 VerStr
= string(Data
,0,Data
.length()-1);
53 // All empty = match all
60 // Are we a simple specification?
61 string::const_iterator I
= Data
.begin();
62 for (; I
!= Data
.end() && *I
!= '='; I
++);
71 if (RelVerStr
.length() > 0 && RelVerStr
.end()[-1] == '*')
73 RelVerPrefixMatch
= true;
74 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
81 snprintf(Spec
,sizeof(Spec
),"%s",Data
.c_str());
82 if (TokSplitString(',',Spec
,Fragments
,
83 sizeof(Fragments
)/sizeof(Fragments
[0])) == false)
89 for (unsigned J
= 0; Fragments
[J
] != 0; J
++)
91 if (strlen(Fragments
[J
]) < 3)
94 if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"v=") == 0)
95 RelVerStr
= Fragments
[J
]+2;
96 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"o=") == 0)
97 RelOrigin
= Fragments
[J
]+2;
98 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"a=") == 0)
99 RelArchive
= Fragments
[J
]+2;
100 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"l=") == 0)
101 RelLabel
= Fragments
[J
]+2;
102 else if (stringcasecmp(Fragments
[J
],Fragments
[J
]+2,"c=") == 0)
103 RelComponent
= Fragments
[J
]+2;
106 if (RelVerStr
.end()[-1] == '*')
108 RelVerPrefixMatch
= true;
109 RelVerStr
= string(RelVerStr
.begin(),RelVerStr
.end()-1);
121 // VersionMatch::MatchVer - Match a version string with prefixing /*{{{*/
122 // ---------------------------------------------------------------------
124 bool pkgVersionMatch::MatchVer(const char *A
,string B
,bool Prefix
)
127 const char *Ae
= Ab
+ strlen(A
);
129 // Strings are not a compatible size.
130 if ((unsigned)(Ae
- Ab
) != B
.length() && Prefix
== false ||
131 (unsigned)(Ae
- Ab
) < B
.length())
135 if (stringcasecmp(B
,Ab
,Ab
+ B
.length()) == 0)
141 // VersionMatch::Find - Locate the best match for the select type /*{{{*/
142 // ---------------------------------------------------------------------
144 pkgCache::VerIterator
pkgVersionMatch::Find(pkgCache::PkgIterator Pkg
)
146 pkgCache::VerIterator Ver
= Pkg
.VersionList();
147 for (; Ver
.end() == false; Ver
++)
151 if (MatchVer(Ver
.VerStr(),VerStr
,VerPrefixMatch
) == true)
156 for (pkgCache::VerFileIterator VF
= Ver
.FileList(); VF
.end() == false; VF
++)
157 if (FileMatch(VF
.File()) == true)
161 // This will be Ended by now.
165 // VersionMatch::FileMatch - Match against an index file /*{{{*/
166 // ---------------------------------------------------------------------
167 /* This matcher checks against the release file and the origin location
168 to see if the constraints are met. */
169 bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File
)
173 if (MatchAll
== true)
176 /* cout << RelVerStr << ',' << RelOrigin << ',' << RelArchive << ',' << RelLabel << endl;
177 cout << File.Version() << ',' << File.Origin() << ',' << File.Archive() << ',' << File.Label() << endl;*/
179 if (RelVerStr
.empty() == true && RelOrigin
.empty() == true &&
180 RelArchive
.empty() == true && RelLabel
.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)
194 if (File
->Archive
== 0 ||
195 stringcasecmp(RelArchive
,File
.Archive()) != 0)
198 if (RelLabel
.empty() == false)
199 if (File
->Label
== 0 ||
200 stringcasecmp(RelLabel
,File
.Label()) != 0)
202 if (RelComponent
.empty() == false)
203 if (File
->Component
== 0 ||
204 stringcasecmp(RelComponent
,File
.Component()) != 0)
211 if (OrSite
.empty() == false) {
212 if (File
->Site
== 0 || OrSite
!= File
.Site())
214 } else // so we are talking about file:// or status file
215 if (strcmp(File
.Site(),"") == 0 && File
->Archive
!= 0) // skip the status file
217 return (OrSite
== File
.Site()); /* both strings match */