chore: simplify dlcache initialization
This commit is contained in:
		| @@ -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) | 		err := dl.Download(ctx, opts) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
|   | |||||||
| @@ -155,7 +155,7 @@ func TestDownloadFileWithCache(t *testing.T) { | |||||||
| 				CacheDisabled: false, | 				CacheDisabled: false, | ||||||
| 				URL:           server.URL + "/file", | 				URL:           server.URL + "/file", | ||||||
| 				Destination:   tmpdir, | 				Destination:   tmpdir, | ||||||
| 				DlCache:       dlcache.New(cfg), | 				DlCache:       dlcache.New(cfg.GetPaths().CacheDir), | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			outputFile := path.Join(tmpdir, "file") | 			outputFile := path.Join(tmpdir, "file") | ||||||
|   | |||||||
| @@ -32,19 +32,15 @@ type Config interface { | |||||||
| } | } | ||||||
|  |  | ||||||
| type DownloadCache struct { | type DownloadCache struct { | ||||||
| 	cfg Config | 	cacheDir string | ||||||
| } | } | ||||||
|  |  | ||||||
| func New(cfg Config) *DownloadCache { | func New(cacheDir string) *DownloadCache { | ||||||
| 	return &DownloadCache{ | 	return &DownloadCache{cacheDir} | ||||||
| 		cfg, |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (dc *DownloadCache) BasePath(ctx context.Context) string { | func (dc *DownloadCache) BasePath(ctx context.Context) string { | ||||||
| 	return filepath.Join( | 	return filepath.Join(dc.cacheDir, "dl") | ||||||
| 		dc.cfg.GetPaths().CacheDir, "dl", |  | ||||||
| 	) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // New creates a new directory with the given ID in the cache. | // New creates a new directory with the given ID in the cache. | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ func TestNew(t *testing.T) { | |||||||
| 	cfg := prepare(t) | 	cfg := prepare(t) | ||||||
| 	defer cleanup(t, cfg) | 	defer cleanup(t, cfg) | ||||||
|  |  | ||||||
| 	dc := dlcache.New(cfg) | 	dc := dlcache.New(cfg.GetPaths().CacheDir) | ||||||
|  |  | ||||||
| 	ctx := context.Background() | 	ctx := context.Background() | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user