dnf:fix install error when vim file in /etc/dnf/vars/

This commit is contained in:
chenhaxing 2023-02-17 15:01:02 +08:00
parent 1342bf24c5
commit 609d5008ea
2 changed files with 60 additions and 1 deletions

View File

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

View File

@ -3,7 +3,7 @@
Name: dnf
Version: 4.14.0
Release: 9
Release: 10
Summary: A software package manager that manages packages on Linux distributions.
License: GPLv2+ and GPLv2 and GPL
URL: https://github.com/rpm-software-management/dnf
@ -27,6 +27,7 @@ Patch6000: dnf-4.10.0-sw.patch
Patch6001: 0001-Add-loongarch-architecture-support.patch
%endif
Patch6002: backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch
Patch6003: backport-ignore-processing-variable-files-with-unsupported-encoding.patch
BuildArch: noarch
BuildRequires: cmake gettext systemd bash-completion python3-sphinx
@ -251,6 +252,12 @@ popd
%{_mandir}/man8/%{name}-automatic.8*
%changelog
* Fri Feb 17 2023 chenhaixing <chenhaixing@huawei.com> 4.14.0-10
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:dnf:fix install error when vim file in /etc/dnf/vars/
* Tue Jan 10 2023 xiasenlin <xiasenlin1@huawei.com> - 4.14.0-9
- DESC:add get-lockfile-exists-before-unlick.patch