From f12dcb714885028e79941aaa060c70c59c57bb2a Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Wed, 25 Dec 2024 13:36:08 +0300 Subject: [PATCH] #55 additional context handle --- compose/downloadManager.go | 53 +++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/compose/downloadManager.go b/compose/downloadManager.go index 48e2441..04e1e50 100644 --- a/compose/downloadManager.go +++ b/compose/downloadManager.go @@ -72,37 +72,42 @@ func (m DownloadManager) Download(ctx context.Context, c *YamlCompose, targetDir func (m DownloadManager) recursiveDownload(ctx context.Context, yc *YamlCompose, kw *keyringWrapper, packages []*Package, parent *Package, targetDir string) ([]*Package, error) { for _, d := range yc.Dependencies { - // build package from dependency struct - // add dependency if parent exists - pkg := d.ToPackage(d.Name) - if parent != nil { - parent.AddDependency(d.Name) - } + select { + case <-ctx.Done(): + return packages, ctx.Err() + default: + // build package from dependency struct + // add dependency if parent exists + pkg := d.ToPackage(d.Name) + if parent != nil { + parent.AddDependency(d.Name) + } - url := pkg.GetURL() - if url == "" { - return packages, errNoURL - } + url := pkg.GetURL() + if url == "" { + return packages, errNoURL + } - packagePath := filepath.Join(targetDir, pkg.GetName(), pkg.GetTarget()) + packagePath := filepath.Join(targetDir, pkg.GetName(), pkg.GetTarget()) - err := downloadPackage(ctx, pkg, targetDir, kw) - if err != nil { - return packages, err - } + err := downloadPackage(ctx, pkg, targetDir, kw) + if err != nil { + return packages, err + } - // If package has plasma-compose.yaml, proceed with it - if _, err = os.Stat(filepath.Join(packagePath, composeFile)); !os.IsNotExist(err) { - cfg, err := Lookup(os.DirFS(packagePath)) - if err == nil { - packages, err = m.recursiveDownload(ctx, cfg, kw, packages, pkg, targetDir) - if err != nil { - return packages, err + // If package has plasma-compose.yaml, proceed with it + if _, err = os.Stat(filepath.Join(packagePath, composeFile)); !os.IsNotExist(err) { + cfg, err := Lookup(os.DirFS(packagePath)) + if err == nil { + packages, err = m.recursiveDownload(ctx, cfg, kw, packages, pkg, targetDir) + if err != nil { + return packages, err + } } } - } - packages = append(packages, pkg) + packages = append(packages, pkg) + } } return packages, nil