CleanupPrefixComponentFiles removes all unreferenced files in published storage under prefix/component pair
(publishedStorageProvider aptly.PublishedStorageProvider, published *PublishedRepo, cleanComponents []string, collectionFactory *CollectionFactory, progress aptly.Progress)
| 1655 | |
| 1656 | // CleanupPrefixComponentFiles removes all unreferenced files in published storage under prefix/component pair |
| 1657 | func (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 { |
no test coverage detected