MCPcopy Create free account
hub / github.com/aptly-dev/aptly / DownloadAppStreamFiles

Method DownloadAppStreamFiles

deb/remote.go:292–352  ·  view source on GitHub ↗

DownloadAppStreamFiles downloads AppStream (DEP-11) metadata files and imports them into the pool

(progress aptly.Progress, d aptly.Downloader,
	packagePool aptly.PackagePool, checksumStorage aptly.ChecksumStorage, ignoreChecksums bool)

Source from the content-addressed store, hash-verified

290
291// DownloadAppStreamFiles downloads AppStream (DEP-11) metadata files and imports them into the pool
292func (repo *RemoteRepo) DownloadAppStreamFiles(progress aptly.Progress, d aptly.Downloader,
293 packagePool aptly.PackagePool, checksumStorage aptly.ChecksumStorage, ignoreChecksums bool) error {
294
295 repo.AppStreamFiles = make(map[string]string)
296
297 for _, component := range repo.Components {
298 paths := repo.AppStreamPaths(component)
299 if len(paths) == 0 {
300 continue
301 }
302
303 for _, relativePath := range paths {
304 info, ok := repo.ReleaseFiles[relativePath]
305 if !ok {
306 continue
307 }
308
309 url := repo.IndexesRootURL().ResolveReference(&url.URL{Path: relativePath}).String()
310
311 if progress != nil {
312 progress.Printf("Downloading AppStream file %s...\n", relativePath)
313 }
314
315 tempDir, err := os.MkdirTemp("", "aptly-appstream-*")
316 if err != nil {
317 return fmt.Errorf("unable to create temp dir for AppStream file %s: %s", relativePath, err)
318 }
319
320 tempPath := path.Join(tempDir, path.Base(relativePath))
321
322 var expected *utils.ChecksumInfo
323 if !ignoreChecksums {
324 expected = &info
325 }
326
327 err = d.DownloadWithChecksum(gocontext.TODO(), url, tempPath, expected, ignoreChecksums)
328 if err != nil {
329 _ = os.RemoveAll(tempDir)
330 // Skip files that are not found (some repos list dep11 files but don't serve them)
331 if herr, ok := err.(*http.Error); ok && (herr.Code == 404 || herr.Code == 403) {
332 if progress != nil {
333 progress.ColoredPrintf("@y[!]@| @!skipping AppStream file %s: not found@|", relativePath)
334 }
335 continue
336 }
337 return fmt.Errorf("unable to download AppStream file %s: %s", relativePath, err)
338 }
339
340 basename := path.Base(relativePath)
341 poolPath, err := packagePool.Import(tempPath, basename, &info, true, checksumStorage)
342 _ = os.RemoveAll(tempDir)
343 if err != nil {
344 return fmt.Errorf("unable to import AppStream file %s: %s", relativePath, err)
345 }
346
347 repo.AppStreamFiles[relativePath] = poolPath
348 }
349 }

Callers 3

aptlyMirrorUpdateFunction · 0.80
apiMirrorsUpdateFunction · 0.80

Calls 7

AppStreamPathsMethod · 0.95
IndexesRootURLMethod · 0.95
StringMethod · 0.65
PrintfMethod · 0.65
DownloadWithChecksumMethod · 0.65
ColoredPrintfMethod · 0.65
ImportMethod · 0.65

Tested by 1