From 02423af931af502b3b0f174f90109cb1319a15fa Mon Sep 17 00:00:00 2001 From: Philip Cramer <107579314+PhilipCramer@users.noreply.github.com> Date: Thu, 26 Feb 2026 22:03:03 +0100 Subject: [PATCH] fix: prevent db cleanup from deleting AppStream pool files --- cmd/db_cleanup.go | 11 +++++++++++ system/t08_db/CleanupDB13Test_gold | 7 +++++++ system/t08_db/CleanupDB13Test_publish | 14 ++++++++++++++ system/t08_db/cleanup.py | 24 ++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 system/t08_db/CleanupDB13Test_gold create mode 100644 system/t08_db/CleanupDB13Test_publish diff --git a/cmd/db_cleanup.go b/cmd/db_cleanup.go index c079955e..f3b52b23 100644 --- a/cmd/db_cleanup.go +++ b/cmd/db_cleanup.go @@ -26,6 +26,7 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error { // collect information about references packages... existingPackageRefs := deb.NewPackageRefList() + referencedAppStreamFiles := []string{} // used only in verbose mode to report package use source packageRefSources := map[string][]string{} @@ -55,6 +56,10 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error { } } + for _, poolPath := range repo.AppStreamFiles { + referencedAppStreamFiles = append(referencedAppStreamFiles, poolPath) + } + return nil }) if err != nil { @@ -118,6 +123,11 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error { return nil }) } + + for _, poolPath := range snapshot.AppStreamFiles { + referencedAppStreamFiles = append(referencedAppStreamFiles, poolPath) + } + return nil }) if err != nil { @@ -236,6 +246,7 @@ func aptlyDBCleanup(cmd *commander.Command, args []string) error { return err } + referencedFiles = append(referencedFiles, referencedAppStreamFiles...) sort.Strings(referencedFiles) context.Progress().ShutdownBar() diff --git a/system/t08_db/CleanupDB13Test_gold b/system/t08_db/CleanupDB13Test_gold new file mode 100644 index 00000000..138adc29 --- /dev/null +++ b/system/t08_db/CleanupDB13Test_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/CleanupDB13Test_publish b/system/t08_db/CleanupDB13Test_publish new file mode 100644 index 00000000..740f9154 --- /dev/null +++ b/system/t08_db/CleanupDB13Test_publish @@ -0,0 +1,14 @@ +Loading packages... +Generating metadata files and linking package files... +[!] Failed to generate package contents: unable to read .deb archive from amanda-client_3.3.1-3~bpo60+1_amd64.deb: ar: missing global header +Finalizing metadata files... +Signing file 'Release' with gpg, please enter your passphrase when prompted: +Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: + +Snapshot snap-appstream has been successfully published. +Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing. +Now you can add following line to apt sources: + deb http://your-server/ hardy main +Don't forget to add your GPG key to apt with apt-key. + +You can also use `aptly serve` to publish your repositories over HTTP quickly. diff --git a/system/t08_db/cleanup.py b/system/t08_db/cleanup.py index c0633426..ff8bef0d 100644 --- a/system/t08_db/cleanup.py +++ b/system/t08_db/cleanup.py @@ -150,3 +150,27 @@ class CleanupDB12Test(BaseTest): "aptly mirror drop gnuplot-maverick", ] runCmd = "aptly db cleanup -verbose -dry-run" + + +class CleanupDB13Test(BaseTest): + """ + cleanup db: appstream files survive cleanup + """ + fixtureWebServer = "../t04_mirror/test_release2" + fixtureGpg = True + configOverride = {"downloadRetries": 0} + fixtureCmds = [ + "aptly mirror create --ignore-signatures -with-appstream -architectures=amd64 appstream-test ${url} hardy main", + "aptly mirror update -ignore-checksums --ignore-signatures appstream-test", + "aptly snapshot create snap-appstream from mirror appstream-test", + ] + runCmd = "aptly db cleanup" + + def check(self): + self.check_output() + # verify appstream files survive cleanup by publishing the snapshot + self.check_cmd_output( + "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap-appstream", + "publish", match_prepare=self.expand_environ) + self.check_exists('public/dists/hardy/main/dep11/Components-amd64.yml.gz') + self.check_exists('public/dists/hardy/main/dep11/icons-48x48.tar.gz')