Blame SOURCES/0039-Ignore-processing-variable-files-with-unsupported-en.patch

eb8139
From 23742561dcb168604d9668815a8c1ebbdf516d39 Mon Sep 17 00:00:00 2001
eb8139
From: Jan Kolarik <jkolarik@redhat.com>
eb8139
Date: Wed, 23 Nov 2022 08:44:41 +0000
eb8139
Subject: [PATCH 2/2] Ignore processing variable files with unsupported
eb8139
 encoding (RhBug:2141215)
eb8139
eb8139
This issue could be seen for example when there are some temporary files stored by text editors in the `/etc/dnf/vars` folder. These files could be in the binary format and causes `UnicodeDecodeError` exception to be thrown during processing of the var files.
eb8139
eb8139
= changelog =
eb8139
type: bugfix
eb8139
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2141215
eb8139
---
eb8139
 dnf/conf/substitutions.py | 9 ++++++---
eb8139
 1 file changed, 6 insertions(+), 3 deletions(-)
eb8139
eb8139
diff --git a/dnf/conf/substitutions.py b/dnf/conf/substitutions.py
eb8139
index 1281bdf0..4d0f0d55 100644
eb8139
--- a/dnf/conf/substitutions.py
eb8139
+++ b/dnf/conf/substitutions.py
eb8139
@@ -18,13 +18,15 @@
eb8139
 # Red Hat, Inc.
eb8139
 #
eb8139
 
eb8139
+import logging
eb8139
 import os
eb8139
 import re
eb8139
 
eb8139
-import dnf
eb8139
-import dnf.exceptions
eb8139
+from dnf.i18n import _
eb8139
 
eb8139
 ENVIRONMENT_VARS_RE = re.compile(r'^DNF_VAR_[A-Za-z0-9_]+$')
eb8139
+logger = logging.getLogger('dnf')
eb8139
+
eb8139
 
eb8139
 class Substitutions(dict):
eb8139
     # :api
eb8139
@@ -60,7 +62,8 @@ class Substitutions(dict):
eb8139
                             val = fp.readline()
eb8139
                         if val and val[-1] == '\n':
eb8139
                             val = val[:-1]
eb8139
-                    except (OSError, IOError):
eb8139
+                    except (OSError, IOError, UnicodeDecodeError) as e:
eb8139
+                        logger.warning(_("Error when parsing a variable from file '{0}': {1}").format(filepath, e))
eb8139
                         continue
eb8139
                 if val is not None:
eb8139
                     self[fsvar] = val
eb8139
-- 
eb8139
2.39.0
eb8139