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

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