16
16
package packagemanager
17
17
18
18
import (
19
+ "context"
19
20
"fmt"
20
21
"net/url"
21
22
@@ -32,15 +33,15 @@ import (
32
33
33
34
// LoadHardwareForProfile load the hardware platforms for the given profile.
34
35
// If installMissing is true then possibly missing tools and platforms will be downloaded and installed.
35
- func (pmb * Builder ) LoadHardwareForProfile (p * sketch.Profile , installMissing bool , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB , settings * configuration.Settings ) []error {
36
+ func (pmb * Builder ) LoadHardwareForProfile (ctx context. Context , p * sketch.Profile , installMissing bool , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB , settings * configuration.Settings ) []error {
36
37
pmb .profile = p
37
38
38
39
// Load required platforms
39
40
var merr []error
40
41
var platformReleases []* cores.PlatformRelease
41
42
indexURLs := map [string ]* url.URL {}
42
43
for _ , platformRef := range p .Platforms {
43
- if platformRelease , err := pmb .loadProfilePlatform (platformRef , installMissing , downloadCB , taskCB , settings ); err != nil {
44
+ if platformRelease , err := pmb .loadProfilePlatform (ctx , platformRef , installMissing , downloadCB , taskCB , settings ); err != nil {
44
45
merr = append (merr , fmt .Errorf ("%s: %w" , tr ("loading required platform %s" , platformRef ), err ))
45
46
logrus .WithField ("platform" , platformRef ).WithError (err ).Debugf ("Error loading platform for profile" )
46
47
} else {
@@ -68,7 +69,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
68
69
return merr
69
70
}
70
71
71
- func (pmb * Builder ) loadProfilePlatform (platformRef * sketch.ProfilePlatformReference , installMissing bool , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB , settings * configuration.Settings ) (* cores.PlatformRelease , error ) {
72
+ func (pmb * Builder ) loadProfilePlatform (ctx context. Context , platformRef * sketch.ProfilePlatformReference , installMissing bool , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB , settings * configuration.Settings ) (* cores.PlatformRelease , error ) {
72
73
targetPackage := pmb .packages .GetOrCreatePackage (platformRef .Packager )
73
74
platform := targetPackage .GetOrCreatePlatform (platformRef .Architecture )
74
75
release := platform .GetOrCreateRelease (platformRef .Version )
@@ -77,14 +78,14 @@ func (pmb *Builder) loadProfilePlatform(platformRef *sketch.ProfilePlatformRefer
77
78
destDir := settings .ProfilesCacheDir ().Join (uid )
78
79
if ! destDir .IsDir () && installMissing {
79
80
// Try installing the missing platform
80
- if err := pmb .installMissingProfilePlatform (platformRef , destDir , downloadCB , taskCB ); err != nil {
81
+ if err := pmb .installMissingProfilePlatform (ctx , platformRef , destDir , downloadCB , taskCB ); err != nil {
81
82
return nil , err
82
83
}
83
84
}
84
85
return release , pmb .loadPlatformRelease (release , destDir )
85
86
}
86
87
87
- func (pmb * Builder ) installMissingProfilePlatform (platformRef * sketch.ProfilePlatformReference , destDir * paths.Path , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ) error {
88
+ func (pmb * Builder ) installMissingProfilePlatform (ctx context. Context , platformRef * sketch.ProfilePlatformReference , destDir * paths.Path , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ) error {
88
89
// Instantiate a temporary package manager only for platform installation
89
90
_ = pmb .tempDir .MkdirAll ()
90
91
tmp , err := paths .MkTempDir (pmb .tempDir .String (), "" )
@@ -103,7 +104,7 @@ func (pmb *Builder) installMissingProfilePlatform(platformRef *sketch.ProfilePla
103
104
}
104
105
for _ , indexURL := range indexesToDownload {
105
106
indexResource := resources.IndexResource {URL : indexURL }
106
- if err := indexResource .Download (tmpPmb .IndexDir , downloadCB , pmb .downloaderConfig ); err != nil {
107
+ if err := indexResource .Download (ctx , tmpPmb .IndexDir , downloadCB , pmb .downloaderConfig ); err != nil {
107
108
taskCB (& rpc.TaskProgress {Name : tr ("Error downloading %s" , indexURL )})
108
109
return & cmderrors.FailedDownloadError {Message : tr ("Error downloading %s" , indexURL ), Cause : err }
109
110
}
0 commit comments