From a600097a8f5ab9f0083a9abb906e0a0b5394176c Mon Sep 17 00:00:00 2001 From: Inessa Vasilevskaya Date: Wed, 8 Mar 2023 12:12:51 +0100 Subject: [PATCH 17/30] Fix false positive non-utf symlinks reported Because of botched up check for python2 valid utf symlinks were reported as non-utf ones. OAMG-8629 --- .../system_upgrade/common/actors/rootscanner/actor.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/repos/system_upgrade/common/actors/rootscanner/actor.py b/repos/system_upgrade/common/actors/rootscanner/actor.py index 515fd7d7..dc02c7a2 100644 --- a/repos/system_upgrade/common/actors/rootscanner/actor.py +++ b/repos/system_upgrade/common/actors/rootscanner/actor.py @@ -28,8 +28,16 @@ class RootScanner(Actor): return subdir_cls(name=name) for subdir in os.listdir('/'): - # Note(ivasilev) non-utf encoded string will appear as byte strings + # Note(ivasilev) in py3 env non-utf encoded string will appear as byte strings + # However in py2 env subdir will be always of str type, so verification if this is a valid utf-8 string + # should be done differently than formerly suggested plain six.binary_type check + decoded = True if isinstance(subdir, six.binary_type): + try: + subdir.decode('utf-8') + except (AttributeError, UnicodeDecodeError): + decoded = False + if not decoded: invalid_subdirs.append(_create_a_subdir(InvalidRootSubdirectory, subdir, os.path.join(b'/', subdir))) else: subdirs.append(_create_a_subdir(RootSubdirectory, subdir, os.path.join('/', subdir))) -- 2.40.1