Skip to content

Commit

Permalink
{pre,post}-transaction-actions: fix package files filtering regression
Browse files Browse the repository at this point in the history
According to DNF User's FAQ, starting with Fedora 40 filelists metadata
became optional. This caused a regression in pre and post transaction
actions plugins which rely on this information. Let's request filelists
metadata whenever the pre or post transaction actions plugin is enabled
and at least one action line contains a file pattern.

= changelog =
msg: Fix package files filtering in pre and post-transaction-actions plugins
type: bugfix
  • Loading branch information
kszczek committed Jun 13, 2024
1 parent 2ad7d93 commit be2a6c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions plugins/post-transaction-actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import libdnf.conf
import dnf
import dnf.transaction
import dnf.util
import glob
import os
import subprocess
Expand All @@ -45,13 +46,22 @@ def __init__(self, base, cli):
self.actiondir = "/etc/dnf/plugins/post-transaction-actions.d/"
self.base = base
self.logger = logger
self.action_tuples = None

def config(self):
conf = self.read_config(self.base.conf)
if conf.has_section("main"):
if conf.has_option("main", "actiondir"):
self.actiondir = conf.get("main", "actiondir")

if "filelists" not in self.base.conf.optional_metadata_types:
if self.action_tuples is None:
self.action_tuples = self._parse_actions()
for (a_key, _, _) in self.action_tuples:
if dnf.util._is_file_pattern_present(a_key):
self.base.conf.optional_metadata_types += ["filelists"]
break

def _parse_actions(self):
"""Parses *.action files from self.actiondir path.
Parsed actions are stored in a list of tuples."""
Expand Down Expand Up @@ -105,7 +115,8 @@ def _replace_vars(self, ts_item, command):
return result

def transaction(self):
action_tuples = self._parse_actions()
if self.action_tuples is None:
self.action_tuples = self._parse_actions()

in_ts_items = []
out_ts_items = []
Expand All @@ -121,7 +132,7 @@ def transaction(self):
all_ts_items.append(ts_item)

commands_to_run = []
for (a_key, a_state, a_command) in action_tuples:
for (a_key, a_state, a_command) in self.action_tuples:
if a_state == "in":
ts_items = in_ts_items
elif a_state == "out":
Expand Down
15 changes: 13 additions & 2 deletions plugins/pre-transaction-actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import libdnf.conf
import dnf
import dnf.transaction
import dnf.util
import glob
import os
import subprocess
Expand All @@ -30,13 +31,22 @@ def __init__(self, base, cli):
self.actiondir = "/etc/dnf/plugins/pre-transaction-actions.d/"
self.base = base
self.logger = logger
self.action_tuples = None

def config(self):
conf = self.read_config(self.base.conf)
if conf.has_section("main"):
if conf.has_option("main", "actiondir"):
self.actiondir = conf.get("main", "actiondir")

if "filelists" not in self.base.conf.optional_metadata_types:
if self.action_tuples is None:
self.action_tuples = self._parse_actions()
for (a_key, _, _) in self.action_tuples:
if dnf.util._is_file_pattern_present(a_key):
self.base.conf.optional_metadata_types += ["filelists"]
break

def _parse_actions(self):
"""Parses *.action files from self.actiondir path.
Parsed actions are stored in a list of tuples."""
Expand Down Expand Up @@ -90,7 +100,8 @@ def _replace_vars(self, ts_item, command):
return result

def pre_transaction(self):
action_tuples = self._parse_actions()
if self.action_tuples is None:
self.action_tuples = self._parse_actions()

in_ts_items = []
out_ts_items = []
Expand All @@ -106,7 +117,7 @@ def pre_transaction(self):
all_ts_items.append(ts_item)

commands_to_run = []
for (a_key, a_state, a_command) in action_tuples:
for (a_key, a_state, a_command) in self.action_tuples:
if a_state == "in":
ts_items = in_ts_items
elif a_state == "out":
Expand Down

0 comments on commit be2a6c1

Please sign in to comment.