Skip to content

Commit

Permalink
Fix false positive non-utf symlinks reported
Browse files Browse the repository at this point in the history
Because of botched up check for python2 valid utf symlinks were reported
as non-utf ones.

OAMG-8629
  • Loading branch information
fernflower committed Mar 8, 2023
1 parent 096c3a9 commit 0c114db
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion repos/system_upgrade/common/actors/rootscanner/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ def _create_a_subdir(subdir_cls, name, path):
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)))
Expand Down

0 comments on commit 0c114db

Please sign in to comment.