MCPcopy Index your code
hub / github.com/aptly-dev/aptly / CleanupPrefixComponentFiles

Method CleanupPrefixComponentFiles

deb/publish.go:1657–1782  ·  view source on GitHub ↗

CleanupPrefixComponentFiles removes all unreferenced files in published storage under prefix/component pair

(publishedStorageProvider aptly.PublishedStorageProvider,
	published *PublishedRepo, cleanComponents []string, collectionFactory *CollectionFactory, progress aptly.Progress)

Source from the content-addressed store, hash-verified

1655
1656// CleanupPrefixComponentFiles removes all unreferenced files in published storage under prefix/component pair
1657func (collection *PublishedRepoCollection) CleanupPrefixComponentFiles(publishedStorageProvider aptly.PublishedStorageProvider,
1658 published *PublishedRepo, cleanComponents []string, collectionFactory *CollectionFactory, progress aptly.Progress) error {
1659
1660 var err error
1661
1662 collection.loadList()
1663
1664 storage := published.Storage
1665 prefix := published.Prefix
1666 distribution := published.Distribution
1667
1668 rootPath := filepath.Join(prefix, "dists", distribution)
1669 publishedStorage, err := publishedStorageProvider.GetPublishedStorage(published.Storage)
1670 if err != nil {
1671 return err
1672 }
1673
1674 sort.Strings(cleanComponents)
1675 publishedComponents := published.Components()
1676 removedComponents := utils.StrSlicesSubstract(cleanComponents, publishedComponents)
1677 updatedComponents := utils.StrSlicesSubstract(cleanComponents, removedComponents)
1678
1679 if progress != nil {
1680 progress.Printf("Cleaning up published repository %s/%s...\n", published.StoragePrefix(), distribution)
1681 }
1682
1683 for _, component := range removedComponents {
1684 if progress != nil {
1685 progress.Printf("Removing component '%s'...\n", component)
1686 }
1687
1688 err = publishedStorage.RemoveDirs(filepath.Join(rootPath, component), progress)
1689 if err != nil {
1690 return err
1691 }
1692
1693 // Ensure that component does not exist in multi distribution pool
1694 err = publishedStorage.RemoveDirs(filepath.Join(prefix, "pool", distribution, component), nil)
1695 if err != nil {
1696 return err
1697 }
1698 }
1699
1700 referencedFiles := map[string][]string{}
1701
1702 if published.MultiDist {
1703 rootPath = filepath.Join(prefix, "pool", distribution)
1704
1705 // Get all referenced files by component for determining orphaned pool files.
1706 for _, component := range publishedComponents {
1707 packageList, err := NewPackageListFromRefList(published.RefList(component), collectionFactory.PackageCollection(), progress)
1708 if err != nil {
1709 return err
1710 }
1711
1712 _ = packageList.ForEach(func(p *Package) error {
1713 poolDir, err := p.PoolDirectory()
1714 if err != nil {

Callers 6

RemoveMethod · 0.95
aptlyPublishUpdateFunction · 0.80
aptlyPublishSwitchFunction · 0.80
apiPublishUpdateSwitchFunction · 0.80
apiPublishUpdateFunction · 0.80

Calls 15

loadListMethod · 0.95
StrSlicesSubstractFunction · 0.92
StoragePrefixMethod · 0.80
PackageCollectionMethod · 0.80
PoolDirectoryMethod · 0.80
FilesMethod · 0.80
GetPublishedStorageMethod · 0.65
PrintfMethod · 0.65
RemoveDirsMethod · 0.65
FilelistMethod · 0.65

Tested by

no test coverage detected