Refactor to embed gocontext.Context into aptly context

This commit is contained in:
Andrey Smirnov
2017-11-30 23:44:04 +03:00
parent 15618c8ea8
commit b7490fe909
2 changed files with 7 additions and 15 deletions
+4 -4
View File
@@ -136,7 +136,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
for idx := range queue { for idx := range queue {
select { select {
case downloadQueue <- idx: case downloadQueue <- idx:
case <-context.GoContext().Done(): case <-context.Done():
return return
} }
} }
@@ -169,7 +169,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
// download file... // download file...
e = context.Downloader().DownloadWithChecksum( e = context.Downloader().DownloadWithChecksum(
context.GoContext(), context,
repo.PackageURL(task.File.DownloadURL()).String(), repo.PackageURL(task.File.DownloadURL()).String(),
task.TempDownPath, task.TempDownPath,
&task.File.Checksums, &task.File.Checksums,
@@ -181,7 +181,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
} }
task.Done = true task.Done = true
case <-context.GoContext().Done(): case <-context.Done():
return return
} }
} }
@@ -227,7 +227,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
context.Progress().ShutdownBar() context.Progress().ShutdownBar()
select { select {
case <-context.GoContext().Done(): case <-context.Done():
return fmt.Errorf("unable to update: interrupted") return fmt.Errorf("unable to update: interrupted")
default: default:
} }
+3 -11
View File
@@ -32,7 +32,7 @@ import (
type AptlyContext struct { type AptlyContext struct {
sync.Mutex sync.Mutex
ctx gocontext.Context gocontext.Context
flags, globalFlags *flag.FlagSet flags, globalFlags *flag.FlagSet
configLoaded bool configLoaded bool
@@ -442,14 +442,6 @@ func (context *AptlyContext) GlobalFlags() *flag.FlagSet {
return context.globalFlags return context.globalFlags
} }
// GoContext returns instance of Go context.Context for the current session
func (context *AptlyContext) GoContext() gocontext.Context {
context.Lock()
defer context.Unlock()
return context.ctx
}
// GoContextHandleSignals upgrades context to handle ^C by aborting context // GoContextHandleSignals upgrades context to handle ^C by aborting context
func (context *AptlyContext) GoContextHandleSignals() { func (context *AptlyContext) GoContextHandleSignals() {
context.Lock() context.Lock()
@@ -461,7 +453,7 @@ func (context *AptlyContext) GoContextHandleSignals() {
var cancel gocontext.CancelFunc var cancel gocontext.CancelFunc
context.ctx, cancel = gocontext.WithCancel(context.ctx) context.Context, cancel = gocontext.WithCancel(context.Context)
go func() { go func() {
<-sigch <-sigch
@@ -527,7 +519,7 @@ func NewContext(flags *flag.FlagSet) (*AptlyContext, error) {
flags: flags, flags: flags,
globalFlags: flags, globalFlags: flags,
dependencyOptions: -1, dependencyOptions: -1,
ctx: gocontext.TODO(), Context: gocontext.TODO(),
publishedStorages: map[string]aptly.PublishedStorage{}, publishedStorages: map[string]aptly.PublishedStorage{},
} }