[PATCHv2] Beware of parted possibly returning unicode objects (#973019)

Vratislav Podzimek vpodzime at redhat.com
Mon Jun 24 14:03:34 UTC 2013


We return plain strings everywhere so we should encode the unicode object with
utf-8 and store it as a plain string.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/__init__.py     | 9 ++++++---
 blivet/devices.py      | 4 ++--
 blivet/partitioning.py | 6 +++---
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index ec828a6..78a0745 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -771,7 +771,8 @@ class Blivet(object):
                 continue
 
             self.recursiveRemove(part)
-            log.debug("partitions: %s" % [p.getDeviceNodeName() for p in part.partedPartition.disk.partitions])
+            log.debug("partitions: %s" % (p.getDeviceNodeName().encode("utf-8")
+                                          for p in part.partedPartition.disk.partitions))
 
         # now remove any empty extended partitions
         self.removeEmptyExtendedPartitions()
@@ -826,10 +827,12 @@ class Blivet(object):
             log.debug("checking whether disk %s has an empty extended" % disk.name)
             extended = disk.format.extendedPartition
             logical_parts = disk.format.logicalPartitions
-            log.debug("extended is %s ; logicals is %s" % (extended, [p.getDeviceNodeName() for p in logical_parts]))
+            log.debug("extended is %s ; logicals is %s" % (extended,
+                                                           (p.getDeviceNodeName().encode("utf-8")
+                                                            for p in logical_parts)))
             if extended and not logical_parts:
                 log.debug("removing empty extended partition from %s" % disk.name)
-                extended_name = devicePathToName(extended.getDeviceNodeName())
+                extended_name = devicePathToName(extended.getDeviceNodeName().encode("utf-8"))
                 extended = self.devicetree.getDeviceByName(extended_name)
                 self.destroyDevice(extended)
 
diff --git a/blivet/devices.py b/blivet/devices.py
index 4877a39..6aa6c26 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -1374,8 +1374,8 @@ class PartitionDevice(StorageDevice):
         if self.partedPartition is None:
             self._name = self.req_name
         else:
-            self._name = \
-                devicePathToName(self.partedPartition.getDeviceNodeName())
+            dev_node_name = self.partedPartition.getDeviceNodeName()
+            self._name = devicePathToName(dev_node_name.encode("utf-8"))
 
     def dependsOn(self, dep):
         """ Return True if this device depends on dep. """
diff --git a/blivet/partitioning.py b/blivet/partitioning.py
index 8660969..cc96228 100644
--- a/blivet/partitioning.py
+++ b/blivet/partitioning.py
@@ -675,7 +675,7 @@ def updateExtendedPartitions(storage, disks):
                         storage.devicetree._removeDevice(part, moddisk=False)
             continue
 
-        extendedName = devicePathToName(extended.getDeviceNodeName())
+        extendedName = devicePathToName(extended.getDeviceNodeName().encode("utf-8"))
         device = storage.devicetree.getDeviceByName(extendedName)
         if device:
             if not device.exists:
@@ -1058,7 +1058,7 @@ def allocatePartitions(storage, disks, partitions, freespace):
 
         partition = addPartition(disklabel, free, part_type, _part.req_size)
         log.debug("created partition %s of %dMB and added it to %s" %
-                (partition.getDeviceNodeName(), partition.getSize(),
+                (partition.getDeviceNodeName().encode("utf-8"), partition.getSize(),
                  disklabel.device))
 
         # this one sets the name
@@ -1870,7 +1870,7 @@ def growPartitions(disks, partitions, free, size_sets=None):
                     # If there was no extended partition on this disk when
                     # doPartitioning was called we won't have a
                     # PartitionDevice instance for it.
-                    name = partition.getDeviceNodeName()
+                    name = partition.getDeviceNodeName().encode("utf-8")
 
                 log.debug("setting %s new geometry: %s" % (name,
                                                            partition.geometry))
-- 
1.7.11.7



More information about the anaconda-patches mailing list