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

Method Remove

deb/publish.go:1785–1853  ·  view source on GitHub ↗

Remove removes published repository, cleaning up directories, files

(publishedStorageProvider aptly.PublishedStorageProvider,
	storage, prefix, distribution string, collectionFactory *CollectionFactory, progress aptly.Progress,
	force, skipCleanup bool)

Source from the content-addressed store, hash-verified

1783
1784// Remove removes published repository, cleaning up directories, files
1785func (collection *PublishedRepoCollection) Remove(publishedStorageProvider aptly.PublishedStorageProvider,
1786 storage, prefix, distribution string, collectionFactory *CollectionFactory, progress aptly.Progress,
1787 force, skipCleanup bool) error {
1788
1789 // TODO: load via transaction
1790 collection.loadList()
1791
1792 repo, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
1793 if err != nil {
1794 return err
1795 }
1796
1797 err = collection.LoadComplete(repo, collectionFactory)
1798 if err != nil {
1799 return err
1800 }
1801
1802 removePrefix := true
1803 removePoolComponents := repo.Components()
1804 cleanComponents := []string{}
1805 repoPosition := -1
1806
1807 for i, r := range collection.list {
1808 if r == repo {
1809 repoPosition = i
1810 continue
1811 }
1812 if r.Storage == repo.Storage && r.Prefix == repo.Prefix {
1813 removePrefix = false
1814
1815 rComponents := r.Components()
1816 for _, component := range rComponents {
1817 if utils.StrSliceHasItem(removePoolComponents, component) {
1818 removePoolComponents = utils.StrSlicesSubstract(removePoolComponents, []string{component})
1819 cleanComponents = append(cleanComponents, component)
1820 }
1821 }
1822 }
1823 }
1824
1825 err = repo.RemoveFiles(publishedStorageProvider, removePrefix, removePoolComponents, progress)
1826 if err != nil {
1827 if !force {
1828 return fmt.Errorf("published files removal failed, use -force-drop to override: %s", err)
1829 }
1830 // ignore error with -force-drop
1831 }
1832
1833 collection.list[len(collection.list)-1], collection.list[repoPosition], collection.list =
1834 nil, collection.list[len(collection.list)-1], collection.list[:len(collection.list)-1]
1835
1836 if !skipCleanup && len(cleanComponents) > 0 {
1837 err = collection.CleanupPrefixComponentFiles(publishedStorageProvider, repo, cleanComponents, collectionFactory, progress)
1838 if err != nil {
1839 if !force {
1840 return fmt.Errorf("cleanup failed, use -force-drop to override: %s", err)
1841 }
1842 }

Callers

nothing calls this directly

Calls 13

loadListMethod · 0.95
LoadCompleteMethod · 0.95
StrSliceHasItemFunction · 0.92
StrSlicesSubstractFunction · 0.92
RemoveFilesMethod · 0.80
CreateBatchMethod · 0.65
DeleteMethod · 0.65
WriteMethod · 0.65
ComponentsMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected