1616package packagemanager
1717
1818import (
19+ "context"
1920 "fmt"
2021 "net/url"
2122
@@ -32,15 +33,15 @@ import (
3233
3334// LoadHardwareForProfile load the hardware platforms for the given profile.
3435// 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 {
3637 pmb .profile = p
3738
3839 // Load required platforms
3940 var merr []error
4041 var platformReleases []* cores.PlatformRelease
4142 indexURLs := map [string ]* url.URL {}
4243 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 {
4445 merr = append (merr , fmt .Errorf ("%s: %w" , tr ("loading required platform %s" , platformRef ), err ))
4546 logrus .WithField ("platform" , platformRef ).WithError (err ).Debugf ("Error loading platform for profile" )
4647 } else {
@@ -68,7 +69,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
6869 return merr
6970}
7071
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 ) {
7273 targetPackage := pmb .packages .GetOrCreatePackage (platformRef .Packager )
7374 platform := targetPackage .GetOrCreatePlatform (platformRef .Architecture )
7475 release := platform .GetOrCreateRelease (platformRef .Version )
@@ -77,14 +78,14 @@ func (pmb *Builder) loadProfilePlatform(platformRef *sketch.ProfilePlatformRefer
7778 destDir := settings .ProfilesCacheDir ().Join (uid )
7879 if ! destDir .IsDir () && installMissing {
7980 // 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 {
8182 return nil , err
8283 }
8384 }
8485 return release , pmb .loadPlatformRelease (release , destDir )
8586}
8687
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 {
8889 // Instantiate a temporary package manager only for platform installation
8990 _ = pmb .tempDir .MkdirAll ()
9091 tmp , err := paths .MkTempDir (pmb .tempDir .String (), "" )
@@ -103,7 +104,7 @@ func (pmb *Builder) installMissingProfilePlatform(platformRef *sketch.ProfilePla
103104 }
104105 for _ , indexURL := range indexesToDownload {
105106 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 {
107108 taskCB (& rpc.TaskProgress {Name : tr ("Error downloading %s" , indexURL )})
108109 return & cmderrors.FailedDownloadError {Message : tr ("Error downloading %s" , indexURL ), Cause : err }
109110 }
0 commit comments