@@ -56,6 +56,14 @@ func NewLoader() *Loader {
5656 }
5757}
5858
59+ // Resource is a convenience abstraction over
60+ // `api.Entry` and `api.ProvidedFile`
61+ // that captures only the necessary information we need
62+ type Resource struct {
63+ Name string // capability name, or file name
64+ Version api.Version // empty for files
65+ }
66+
5967// Load takes a list of all involved packages to install, a list of regular
6068// expressions which denote packages which should be taken into account for
6169// solving the problem, but they should then be ignored together with their
@@ -139,7 +147,8 @@ func (loader *Loader) Load(packages []*api.Package, matched, ignoreRegex, allowR
139147
140148 // Generate variables
141149 for _ , pkg := range packages {
142- pkgVar , resourceVars := loader .explodePackageToVars (pkg )
150+ providedResources := loader .explodeProvidedResources (pkg )
151+ pkgVar , resourceVars := loader .explodePackageToVars (pkg , providedResources )
143152 loader .m .packages [pkg .Name ] = append (loader .m .packages [pkg .Name ], pkgVar )
144153 pkgProvides = append (pkgProvides , resourceVars )
145154 for _ , v := range resourceVars {
@@ -184,52 +193,46 @@ func (loader *Loader) Load(packages []*api.Package, matched, ignoreRegex, allowR
184193 return loader .constructRequirements (matched , archOrder )
185194}
186195
187- func (loader * Loader ) explodePackageToVars (pkg * api.Package ) (pkgVar * Var , resourceVars []* Var ) {
196+ // explodeProvidedResources collects all resources a `pkg` can provide (package, capabilities, files)
197+ // and returns them in unified form of Resource.
198+ func (loader * Loader ) explodeProvidedResources (pkg * api.Package ) (provided []* Resource ) {
199+
188200 for _ , p := range pkg .Format .Provides .Entries {
189- if p .Name == pkg .Name {
190- pkgVar = & Var {
191- satVarName : loader .ticket (),
192- varType : VarTypePackage ,
193- Context : VarContext {
194- PackageKey : pkg .Key (),
195- Provides : pkg .Name ,
196- },
197- Package : pkg ,
198- ResourceVersion : & pkg .Version ,
199- }
200- resourceVars = append (resourceVars , pkgVar )
201- } else {
202- resVar := & Var {
203- satVarName : loader .ticket (),
204- varType : VarTypeResource ,
205- Context : VarContext {
206- PackageKey : pkg .Key (),
207- Provides : p .Name ,
208- },
209- ResourceVersion : & api.Version {
210- Rel : p .Rel ,
211- Ver : p .Ver ,
212- Epoch : p .Epoch ,
213- },
214- Package : pkg ,
215- }
216- resourceVars = append (resourceVars , resVar )
217- }
201+ provided = append (provided , & Resource {
202+ Name : p .Name ,
203+ Version : api.Version {p .Text , p .Epoch , p .Ver , p .Rel },
204+ })
218205 }
219206
220207 for _ , f := range pkg .Format .Files {
221- resVar := & Var {
208+ provided = append (provided , & Resource {
209+ Name : f .Text ,
210+ })
211+ }
212+
213+ return
214+ }
215+
216+ func (loader * Loader ) explodePackageToVars (pkg * api.Package , resources []* Resource ) (pkgVar * Var , resourceVars []* Var ) {
217+ for _ , res := range resources {
218+ newVar := & Var {
222219 satVarName : loader .ticket (),
223- varType : VarTypeFile ,
220+ varType : VarTypeResource ,
224221 Context : VarContext {
225222 PackageKey : pkg .Key (),
226- Provides : f . Text ,
223+ Provides : res . Name ,
227224 },
225+ ResourceVersion : & res .Version ,
228226 Package : pkg ,
229- ResourceVersion : & api.Version {},
230227 }
231- resourceVars = append (resourceVars , resVar )
228+
229+ if res .Name == pkg .Name {
230+ newVar .varType = VarTypePackage
231+ pkgVar = newVar
232+ }
233+ resourceVars = append (resourceVars , newVar )
232234 }
235+
233236 return pkgVar , resourceVars
234237}
235238
0 commit comments