-
-
Notifications
You must be signed in to change notification settings - Fork 398
Fix core upgrade #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix core upgrade #291
Changes from 3 commits
189737a
81fa396
ccba1a0
dcc1d2f
5057a02
311edfa
eed6d58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,11 @@ import ( | |
) | ||
|
||
// Packages represents a set of Packages | ||
type Packages struct { | ||
Packages map[string]*Package // Maps packager name to Package | ||
} | ||
type Packages map[string]*Package // Maps packager name to Package | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no reason for this indirection level that also makes the use of the map awkward by having to repeat |
||
|
||
// NewPackages creates a new Packages object | ||
func NewPackages() *Packages { | ||
return &Packages{ | ||
Packages: map[string]*Package{}, | ||
} | ||
func NewPackages() Packages { | ||
return map[string]*Package{} | ||
} | ||
|
||
// Package represents a package in the system. | ||
|
@@ -44,13 +40,13 @@ type Package struct { | |
Email string // Email of maintainer. | ||
Platforms map[string]*Platform // The platforms in the system. | ||
Tools map[string]*Tool // The tools in the system. | ||
Packages *Packages `json:"-"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now that |
||
Packages Packages `json:"-"` | ||
} | ||
|
||
// GetOrCreatePackage returns the specified Package or create an empty one | ||
// filling all the cross-references | ||
func (packages *Packages) GetOrCreatePackage(packager string) *Package { | ||
if targetPackage, ok := packages.Packages[packager]; ok { | ||
func (packages Packages) GetOrCreatePackage(packager string) *Package { | ||
if targetPackage, ok := packages[packager]; ok { | ||
return targetPackage | ||
} | ||
targetPackage := &Package{ | ||
|
@@ -59,22 +55,46 @@ func (packages *Packages) GetOrCreatePackage(packager string) *Package { | |
Tools: map[string]*Tool{}, | ||
Packages: packages, | ||
} | ||
packages.Packages[packager] = targetPackage | ||
packages[packager] = targetPackage | ||
return targetPackage | ||
} | ||
|
||
// Names returns the array containing the name of the packages. | ||
func (packages *Packages) Names() []string { | ||
res := make([]string, len(packages.Packages)) | ||
func (packages Packages) Names() []string { | ||
res := make([]string, len(packages)) | ||
i := 0 | ||
for n := range packages.Packages { | ||
for n := range packages { | ||
res[i] = n | ||
i++ | ||
} | ||
sortutil.CiAsc(res) | ||
return res | ||
} | ||
|
||
// GetDepsOfPlatformRelease returns the deps of a specified release of a core. | ||
func (packages Packages) GetDepsOfPlatformRelease(release *PlatformRelease) ([]*ToolRelease, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was just moved up in the source module |
||
if release == nil { | ||
return nil, errors.New("release cannot be nil") | ||
} | ||
ret := []*ToolRelease{} | ||
for _, dep := range release.Dependencies { | ||
pkg, exists := packages[dep.ToolPackager] | ||
if !exists { | ||
return nil, fmt.Errorf("package %s not found", dep.ToolPackager) | ||
} | ||
tool, exists := pkg.Tools[dep.ToolName] | ||
if !exists { | ||
return nil, fmt.Errorf("tool %s not found", dep.ToolName) | ||
} | ||
toolRelease, exists := tool.Releases[dep.ToolVersion.String()] | ||
if !exists { | ||
return nil, fmt.Errorf("tool version %s not found", dep.ToolVersion) | ||
} | ||
ret = append(ret, toolRelease) | ||
} | ||
return ret, nil | ||
} | ||
|
||
// GetOrCreatePlatform returns the Platform object with the specified architecture | ||
// or creates a new one if not found | ||
func (targetPackage *Package) GetOrCreatePlatform(architecure string) *Platform { | ||
|
@@ -110,7 +130,7 @@ func (targetPackage *Package) String() string { | |
} | ||
|
||
func (tdep ToolDependency) extractTool(sc Packages) (*Tool, error) { | ||
pkg, exists := sc.Packages[tdep.ToolPackager] | ||
pkg, exists := sc[tdep.ToolPackager] | ||
if !exists { | ||
return nil, errors.New("package not found") | ||
} | ||
|
@@ -132,27 +152,3 @@ func (tdep ToolDependency) extractRelease(sc Packages) (*ToolRelease, error) { | |
} | ||
return release, nil | ||
} | ||
|
||
// GetDepsOfPlatformRelease returns the deps of a specified release of a core. | ||
func (packages *Packages) GetDepsOfPlatformRelease(release *PlatformRelease) ([]*ToolRelease, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see previous comment, this was just moved |
||
if release == nil { | ||
return nil, errors.New("release cannot be nil") | ||
} | ||
ret := []*ToolRelease{} | ||
for _, dep := range release.Dependencies { | ||
pkg, exists := packages.Packages[dep.ToolPackager] | ||
if !exists { | ||
return nil, fmt.Errorf("package %s not found", dep.ToolPackager) | ||
} | ||
tool, exists := pkg.Tools[dep.ToolName] | ||
if !exists { | ||
return nil, fmt.Errorf("tool %s not found", dep.ToolName) | ||
} | ||
toolRelease, exists := tool.Releases[dep.ToolVersion.String()] | ||
if !exists { | ||
return nil, fmt.Errorf("tool version %s not found", dep.ToolVersion) | ||
} | ||
ret = append(ret, toolRelease) | ||
} | ||
return ret, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wasn't used anywhere