Avoid AttributeError for DiskLabel formats without disklabel type (#1945914)

This commit is contained in:
Vojtech Trefny 2021-04-12 13:25:18 +02:00
parent 09da53275c
commit 330f399941
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,38 @@
From bf70f3625e517b73ed45c0d5d40c210124ccd4bc Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Tue, 6 Apr 2021 14:59:41 +0200
Subject: [PATCH] Avoid AttributeError for DiskLabel formats without disklabel
type
Simple instance of DiskLabel without label_type specified in the
constructor results in a AttributeError when trying to print the
format name. This makes sure the name is always valid.
Resolves: rhbz#1945914
---
blivet/formats/disklabel.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 7102457b..c8148309 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -313,13 +313,13 @@ def sector_size(self):
@property
def name(self):
- if self.supported:
- _str = "%(name)s (%(type)s)"
+ if self.label_type is None:
+ return "%(name)s" % {"name": _(self._name)}
+ elif self.supported:
+ return "%(name)s (%(type)s)" % {"name": _(self._name), "type": self.label_type.upper()}
else:
# Translators: Name for an unsupported disklabel; e.g. "Unsupported partition table"
- _str = _("Unsupported %(name)s")
-
- return _str % {"name": _(self._name), "type": self.label_type.upper()}
+ return _("Unsupported %(name)s") % {"name": _(self._name)}
@property
def size(self):

View File

@ -23,7 +23,7 @@ Version: 3.3.3
#%%global prerelease .b2
# prerelease, if defined, should be something like .a1, .b1, .b2.dev1, or .c2
Release: 1%{?prerelease}%{?dist}
Release: 2%{?prerelease}%{?dist}
Epoch: 1
License: LGPLv2+
%global realname blivet
@ -35,6 +35,8 @@ Source1: http://github.com/storaged-project/blivet/archive/%{realname}-%{realver
Patch0: 0001-remove-btrfs-plugin.patch
%endif
Patch1: 0002-Avoid-AttributeError-for-DiskLabel-formats-without-disklabel-type.patch
# Versions of required components (done so we make sure the buildrequires
# match the requires versions of things).
%global partedver 1.8.1
@ -196,6 +198,9 @@ configuration.
%endif
%changelog
* Mon Apr 12 2021 Vojtech Trefny <vtrefny@redhat.com> - 3.3.3-2
- Avoid AttributeError for DiskLabel formats without disklabel type (#1945914)
* Thu Feb 18 2021 Vojtech Trefny <vtrefny@redhat.com> - 3.3.3-1
- apply compression settings from blivet.flags.btrfs_compression (#1926892) (michel)