DownloadTempWithChecksum is a DownloadTemp with checksum verification Temporary file would be already removed, so no need to cleanup
(ctx context.Context, downloader aptly.Downloader, url string, expected *utils.ChecksumInfo, ignoreMismatch bool)
| 20 | // |
| 21 | // Temporary file would be already removed, so no need to cleanup |
| 22 | func DownloadTempWithChecksum(ctx context.Context, downloader aptly.Downloader, url string, expected *utils.ChecksumInfo, ignoreMismatch bool) (*os.File, error) { |
| 23 | tempdir, err := os.MkdirTemp(os.TempDir(), "aptly") |
| 24 | if err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | defer func() { _ = os.RemoveAll(tempdir) }() |
| 28 | |
| 29 | tempfile := filepath.Join(tempdir, "buffer") |
| 30 | |
| 31 | if expected != nil && downloader.GetProgress() != nil { |
| 32 | downloader.GetProgress().InitBar(expected.Size, true, aptly.BarMirrorUpdateDownloadIndexes) |
| 33 | defer downloader.GetProgress().ShutdownBar() |
| 34 | } |
| 35 | |
| 36 | err = downloader.DownloadWithChecksum(ctx, url, tempfile, expected, ignoreMismatch) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | file, err := os.Open(tempfile) |
| 42 | if err != nil { |
| 43 | return nil, err |
| 44 | } |
| 45 | |
| 46 | return file, nil |
| 47 | } |