From 34c549feb8d9bdfb957a0d863a2ae35ff156a641 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sun, 23 Sep 2018 21:01:26 +0200 Subject: [PATCH] [entropy.client] handle correctly encoded file paths too. Historically, Portage + Py2 were not dealing well with file paths that were containing non-ascii chars. The situation has apparently improved and we are able to accept paths with the correct encoding in Entropy (separate patch will come). We need to guard against broken paths anyway, so let's try to check which one of the paths is the one that has the most chance to be the right one. Also, with python3 this won't be a problem anymore... --- .../interfaces/package/actions/_manage.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/entropy/client/interfaces/package/actions/_manage.py b/lib/entropy/client/interfaces/package/actions/_manage.py index ca261c554..754592cf7 100644 --- a/lib/entropy/client/interfaces/package/actions/_manage.py +++ b/lib/entropy/client/interfaces/package/actions/_manage.py @@ -465,10 +465,25 @@ class _PackageInstallRemoveAction(PackageAction): sys_root_item = sys_root + item sys_root_item_encoded = sys_root_item if not const_is_python3(): - # this is coming from the db, and it's pure utf-8 - sys_root_item_encoded = const_convert_to_rawstring( + # this is coming from the db, and it's pure utf-8. + # sometimes we need to deal with broken filesystem + # or path encodings, so we should try both paths, really. + proposed_sys_root_item_encoded = const_convert_to_rawstring( sys_root_item, from_enctype = etpConst['conf_raw_encoding']) + proposed_lexists = os.path.lexists(proposed_sys_root_item_encoded) + old_lexists = os.path.lexists(sys_root_item_encoded) + if proposed_lexists and not old_lexists: + sys_root_item_encoded = proposed_sys_root_item_encoded + elif not proposed_lexists and old_lexists: + # The rawstring version of the path does not exist, while the + # original version does. + # Do not replace sys_root_item_encoded then. + self._entropy.logger.log( + "[Package]", + etpConst['logging']['verbose_loglevel_id'], + "[remove] Package %s contains hostile unicode file paths." % ( + remove_atom,)) # collision check if col_protect > 0: