From 7dec36a4fb9eda06d60864b3cae50c47b35e2a53 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Thu, 27 Jun 2024 14:07:17 +0200 Subject: [PATCH] main: ignore dpkg files when running hook scripts Currently ifupdown2 executes scripts that are backed up by dpkg (e.g. foo.dpkg-old). This can lead to issues with hook scripts getting executed after upgrading ifupdown2 via dpkg, even though they should not be executed. This also brings ifupdown2 closer on par with the behavior of ifupdown, which did not execute hook scripts with dpkg suffixes. Signed-off-by: Stefan Hanreich --- ifupdown2/ifupdown/ifupdownmain.py | 4 +++- ifupdown2/ifupdown/utils.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ifupdown2/ifupdown/ifupdownmain.py b/ifupdown2/ifupdown/ifupdownmain.py index 51f54609..e6622f07 100644 --- a/ifupdown2/ifupdown/ifupdownmain.py +++ b/ifupdown2/ifupdown/ifupdownmain.py @@ -1540,7 +1540,9 @@ def load_scripts(self, modules_dir): try: module_list = os.listdir(msubdir) for module in module_list: - if self.modules.get(module) or module in self.overridden_ifupdown_scripts: + if (self.modules.get(module) + or module in self.overridden_ifupdown_scripts + or utils.is_dpkg_file(module)): continue self.script_ops[op].append(msubdir + '/' + module) except Exception: diff --git a/ifupdown2/ifupdown/utils.py b/ifupdown2/ifupdown/utils.py index 0d0732b3..f33764a6 100644 --- a/ifupdown2/ifupdown/utils.py +++ b/ifupdown2/ifupdown/utils.py @@ -212,6 +212,12 @@ def strip_hwaddress(hwaddress): # what we have in the cache (data retrieved via a netlink dump by # nlmanager). nlmanager return all macs in lower-case + _dpkg_suffixes = (".dpkg-old", ".dpkg-dist", ".dpkg-new", ".dpkg-tmp") + + @staticmethod + def is_dpkg_file(name): + return any(name.endswith(suffix) for suffix in utils._dpkg_suffixes) + @classmethod def importName(cls, modulename, name): """ Import a named object """