From 5e1eeabd040a740d70685e6bfa74128ee0982f28 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Wed, 25 Jun 2025 19:18:11 +0300 Subject: [PATCH] chore: simplify dlcache initialization --- internal/build/source_downloader.go | 2 +- pkg/dl/dl_test.go | 2 +- pkg/dlcache/dlcache.go | 12 ++++-------- pkg/dlcache/dlcache_test.go | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/build/source_downloader.go b/internal/build/source_downloader.go index 7b38be4..bf5f9d6 100644 --- a/internal/build/source_downloader.go +++ b/internal/build/source_downloader.go @@ -74,7 +74,7 @@ func (s *SourceDownloader) DownloadSources( } } - opts.DlCache = dlcache.New(s.cfg) + opts.DlCache = dlcache.New(s.cfg.GetPaths().CacheDir) err := dl.Download(ctx, opts) if err != nil { diff --git a/pkg/dl/dl_test.go b/pkg/dl/dl_test.go index c7326b8..6022c71 100644 --- a/pkg/dl/dl_test.go +++ b/pkg/dl/dl_test.go @@ -155,7 +155,7 @@ func TestDownloadFileWithCache(t *testing.T) { CacheDisabled: false, URL: server.URL + "/file", Destination: tmpdir, - DlCache: dlcache.New(cfg), + DlCache: dlcache.New(cfg.GetPaths().CacheDir), } outputFile := path.Join(tmpdir, "file") diff --git a/pkg/dlcache/dlcache.go b/pkg/dlcache/dlcache.go index ccd654f..2462f68 100644 --- a/pkg/dlcache/dlcache.go +++ b/pkg/dlcache/dlcache.go @@ -32,19 +32,15 @@ type Config interface { } type DownloadCache struct { - cfg Config + cacheDir string } -func New(cfg Config) *DownloadCache { - return &DownloadCache{ - cfg, - } +func New(cacheDir string) *DownloadCache { + return &DownloadCache{cacheDir} } func (dc *DownloadCache) BasePath(ctx context.Context) string { - return filepath.Join( - dc.cfg.GetPaths().CacheDir, "dl", - ) + return filepath.Join(dc.cacheDir, "dl") } // New creates a new directory with the given ID in the cache. diff --git a/pkg/dlcache/dlcache_test.go b/pkg/dlcache/dlcache_test.go index 555cdba..247bad6 100644 --- a/pkg/dlcache/dlcache_test.go +++ b/pkg/dlcache/dlcache_test.go @@ -64,7 +64,7 @@ func TestNew(t *testing.T) { cfg := prepare(t) defer cleanup(t, cfg) - dc := dlcache.New(cfg) + dc := dlcache.New(cfg.GetPaths().CacheDir) ctx := context.Background()