From 391cb7b3226221226eb91e0458fc48770255fc50 Mon Sep 17 00:00:00 2001
From: Joe Talbott <joetalbott@gmail.com>
Date: Sep 22 2021 17:38:59 +0000
Subject: [PATCH 1/3] Prevent kojira from attempting to remove repos on other volumes.


* Adds '--ignore-other-volumes' flag and configuration option.

---

diff --git a/util/kojira b/util/kojira
index 875be9c..b0d32ec 100755
--- a/util/kojira
+++ b/util/kojira
@@ -445,6 +445,15 @@ class RepoManager(object):
                 self.logger.info('Found repo %s, state=%s'
                                  % (repo_id, koji.REPO_STATES[data['state']]))
                 repo = ManagedRepo(self, data, repodata)
+                if self.options.ignore_other_volumes:
+                    info = repo.get_info()
+                    volume = info.get('volume')
+                    if volume is not None and volume != 'DEFAULT':
+                        # Other volume
+                        self.logger.info("Skipping repo ({}) on other volume {}".format(
+                            repo_id, volume,
+                        ))
+                        continue
                 self.repos[repo_id] = repo
             if not getTag(self.session, repo.tag_id) and not repo.expired():
                 self.logger.info('Tag %d for repo %d disappeared, expiring.', repo.tag_id, repo_id)
@@ -635,9 +644,11 @@ class RepoManager(object):
 
     def pruneLocalRepos(self):
         for volinfo in self.session.listVolumes():
-            volumedir = pathinfo.volumedir(volinfo['name'])
-            repodir = "%s/repos" % volumedir
-            self._pruneLocalRepos(repodir, self.options.deleted_repo_lifetime)
+            volname = volinfo['name']
+            volumedir = pathinfo.volumedir(volname)
+            if volname == 'DEFAULT':  # currently the only path for non-dist repos.
+                repodir = "%s/repos" % volumedir
+                self._pruneLocalRepos(repodir, self.options.deleted_repo_lifetime)
             distrepodir = "%s/repos-dist" % volumedir
             self._pruneLocalRepos(distrepodir, self.options.dist_repo_lifetime)
 
@@ -1198,6 +1209,8 @@ def get_options():
     parser.add_option("--logfile", help="Specify logfile")
     parser.add_option("--queue-file",
                       help="If specified, queue is dumped to separate status file each cycle")
+    parser.add_option("--ignore-other-volumes", action="store_true",
+                      help="Ignore repos on other volumes")
     (options, args) = parser.parse_args()
 
     config = koji.read_config_files(options.configFile)
@@ -1235,6 +1248,7 @@ def get_options():
                 'cert': None,
                 'serverca': None,
                 'queue_file': None,
+                'ignore_other_volumes': False,
                 }
     if config.has_section(section):
         int_opts = ('deleted_repo_lifetime', 'max_repo_tasks', 'repo_tasks_limit',
@@ -1245,7 +1259,7 @@ def get_options():
                     'cert', 'serverca', 'debuginfo_tags', 'queue_file',
                     'source_tags', 'separate_source_tags', 'ignore_tags')
         bool_opts = ('verbose', 'debug', 'ignore_stray_repos', 'offline_retry',
-                     'no_ssl_verify', 'check_external_repos')
+                     'no_ssl_verify', 'check_external_repos', 'ignore_other_volumes')
         legacy_opts = ('with_src', 'delete_batch_size', 'recent_tasks_lifetime')
         for name in config.options(section):
             if name in int_opts:

From 23c1c977249553ff83a61b2375f00fbde6c5204a Mon Sep 17 00:00:00 2001
From: Joe Simmons-Talbott <josimmon@redhat.com>
Date: Sep 22 2021 17:38:59 +0000
Subject: [PATCH 2/3] kojira: make 'ignore_other_volumes' a config only option.


* pull 'DEFAULT' repo handling out of the loop.
* Add 'ignore_other_volumes' to kojira.conf

---

diff --git a/util/kojira b/util/kojira
index b0d32ec..92b97d8 100755
--- a/util/kojira
+++ b/util/kojira
@@ -643,12 +643,14 @@ class RepoManager(object):
             session.logout()
 
     def pruneLocalRepos(self):
+        volname = 'DEFAULT'
+        volumedir = pathinfo.volumedir(volname)
+        repodir = "%s/repos" % volumedir
+        self._pruneLocalRepos(repodir, self.options.deleted_repo_lifetime)
+
         for volinfo in self.session.listVolumes():
             volname = volinfo['name']
             volumedir = pathinfo.volumedir(volname)
-            if volname == 'DEFAULT':  # currently the only path for non-dist repos.
-                repodir = "%s/repos" % volumedir
-                self._pruneLocalRepos(repodir, self.options.deleted_repo_lifetime)
             distrepodir = "%s/repos-dist" % volumedir
             self._pruneLocalRepos(distrepodir, self.options.dist_repo_lifetime)
 
@@ -1209,8 +1211,6 @@ def get_options():
     parser.add_option("--logfile", help="Specify logfile")
     parser.add_option("--queue-file",
                       help="If specified, queue is dumped to separate status file each cycle")
-    parser.add_option("--ignore-other-volumes", action="store_true",
-                      help="Ignore repos on other volumes")
     (options, args) = parser.parse_args()
 
     config = koji.read_config_files(options.configFile)
diff --git a/util/kojira.conf b/util/kojira.conf
index e3bb2d0..31160fc 100644
--- a/util/kojira.conf
+++ b/util/kojira.conf
@@ -46,3 +46,6 @@ logfile=/var/log/kojira.log
 ; as otherwise you can end with weird behaviour. For details see
 ; https://pagure.io/koji/issue/2159
 ; check_external_repos = false
+
+; don't attempt to remove repos on non-default volumes
+; ignore_other_volumes = false

From 4c4fb3139fa729f6badbb0e6e5ed2954c22a57b9 Mon Sep 17 00:00:00 2001
From: Joe Simmons-Talbott <josimmon@redhat.com>
Date: Nov 04 2021 12:26:17 +0000
Subject: [PATCH 3/3] Fix for case where 'info' is None.


---

diff --git a/util/kojira b/util/kojira
index 92b97d8..92baede 100755
--- a/util/kojira
+++ b/util/kojira
@@ -447,6 +447,8 @@ class RepoManager(object):
                 repo = ManagedRepo(self, data, repodata)
                 if self.options.ignore_other_volumes:
                     info = repo.get_info()
+                    if info is None:
+                        continue
                     volume = info.get('volume')
                     if volume is not None and volume != 'DEFAULT':
                         # Other volume

