diff --git a/cmd/db_cleanup.go b/cmd/db_cleanup.go index f522ebee..b3400af5 100644 --- a/cmd/db_cleanup.go +++ b/cmd/db_cleanup.go @@ -20,7 +20,7 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { // collect information about references packages... existingPackageRefs := deb.NewPackageRefList() - context.Progress().Printf("Loading mirrors, local repos and snapshots...\n") + context.Progress().Printf("Loading mirrors, local repos, snapshots and published repos...\n") err = context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error { err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo) if err != nil { @@ -61,6 +61,24 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { return err } + err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(published *deb.PublishedRepo) error { + if published.SourceKind != "local" { + return nil + } + err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(published, context.CollectionFactory()) + if err != nil { + return err + } + + for _, component := range published.Components() { + existingPackageRefs = existingPackageRefs.Merge(published.RefList(component), false) + } + return nil + }) + if err != nil { + return err + } + // ... and compare it to the list of all packages context.Progress().Printf("Loading list of all packages...\n") allPackageRefs := context.CollectionFactory().PackageCollection().AllPackageRefs() diff --git a/system/t08_db/CleanupDB1Test_gold b/system/t08_db/CleanupDB1Test_gold index 1816ebdd..138adc29 100644 --- a/system/t08_db/CleanupDB1Test_gold +++ b/system/t08_db/CleanupDB1Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (0)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB2Test_gold b/system/t08_db/CleanupDB2Test_gold index b17771cd..1f289e67 100644 --- a/system/t08_db/CleanupDB2Test_gold +++ b/system/t08_db/CleanupDB2Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (73270)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB3Test_gold b/system/t08_db/CleanupDB3Test_gold index 5f9cd0eb..73279e14 100644 --- a/system/t08_db/CleanupDB3Test_gold +++ b/system/t08_db/CleanupDB3Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (7)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB4Test_gold b/system/t08_db/CleanupDB4Test_gold index 1816ebdd..138adc29 100644 --- a/system/t08_db/CleanupDB4Test_gold +++ b/system/t08_db/CleanupDB4Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (0)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB5Test_gold b/system/t08_db/CleanupDB5Test_gold index 5f9cd0eb..73279e14 100644 --- a/system/t08_db/CleanupDB5Test_gold +++ b/system/t08_db/CleanupDB5Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (7)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB6Test_gold b/system/t08_db/CleanupDB6Test_gold index 1816ebdd..138adc29 100644 --- a/system/t08_db/CleanupDB6Test_gold +++ b/system/t08_db/CleanupDB6Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (0)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB7Test_gold b/system/t08_db/CleanupDB7Test_gold index 1816ebdd..138adc29 100644 --- a/system/t08_db/CleanupDB7Test_gold +++ b/system/t08_db/CleanupDB7Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (0)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB8Test_gold b/system/t08_db/CleanupDB8Test_gold index d5a2e771..fc57cfb9 100644 --- a/system/t08_db/CleanupDB8Test_gold +++ b/system/t08_db/CleanupDB8Test_gold @@ -1,4 +1,4 @@ -Loading mirrors, local repos and snapshots... +Loading mirrors, local repos, snapshots and published repos... Loading list of all packages... Deleting unreferenced packages (3)... Building list of files referenced by packages... diff --git a/system/t08_db/CleanupDB9Test_gold b/system/t08_db/CleanupDB9Test_gold new file mode 100644 index 00000000..138adc29 --- /dev/null +++ b/system/t08_db/CleanupDB9Test_gold @@ -0,0 +1,7 @@ +Loading mirrors, local repos, snapshots and published repos... +Loading list of all packages... +Deleting unreferenced packages (0)... +Building list of files referenced by packages... +Building list of files in package pool... +Deleting unreferenced files (0)... +Compacting database... diff --git a/system/t08_db/CleanupDB9Test_publish_drop b/system/t08_db/CleanupDB9Test_publish_drop new file mode 100644 index 00000000..af8e41e1 --- /dev/null +++ b/system/t08_db/CleanupDB9Test_publish_drop @@ -0,0 +1,4 @@ +Removing /Users/smira/.aptly/public/dists/def... +Cleaning up prefix "." components main... + +Published repository has been removed successfully. diff --git a/system/t08_db/cleanup.py b/system/t08_db/cleanup.py index 0003d16e..79740a24 100644 --- a/system/t08_db/cleanup.py +++ b/system/t08_db/cleanup.py @@ -92,3 +92,22 @@ class CleanupDB8Test(BaseTest): "aptly repo drop local-repo", ] runCmd = "aptly db cleanup" + + +class CleanupDB9Test(BaseTest): + """ + cleanup db: publish local repo, remove packages from repo, db cleanup + """ + fixtureCmds = [ + "aptly repo create -distribution=abc local-repo", + "aptly repo create -distribution=def local-repo2", + "aptly repo add local-repo ${files}", + "aptly publish repo local-repo", + "aptly publish repo -architectures=i386 local-repo2", + "aptly repo remove local-repo Name", + ] + runCmd = "aptly db cleanup" + + def check(self): + self.check_output() + self.check_cmd_output("aptly publish drop def", "publish_drop")