filesystem: use sort path when selecting an application

The method build_select_path_to uses the internal file system tree model
to find the path to a given file. This works the same for applications
(ADF) as it works for normal files (EF/DF). However, an application can
be selected anytime from any location in the filesystem tree. There is
no need to select a specific path leading to that application first.
This means that if there is an ADF somewhere in the resulting
inter_path, we may clip everything before that ADF.

Related: OS#5418
Change-Id: I838a99bb47afc73b4274baecb04fff31abf7b2e2
This commit is contained in:
Philipp Maier 2023-12-13 12:12:32 +01:00
parent 174fd32f17
commit 14bf003dad
1 changed files with 11 additions and 1 deletions

View File

@ -136,6 +136,16 @@ class CardFile:
return ret
def build_select_path_to(self, target: 'CardFile') -> Optional[List['CardFile']]:
# special-case handling for applications. Applications may be selected
# any time from any location. If there is an ADF somewhere in the path,
# we may clip everything before that ADF.
def clip_path(inter_path):
for i in reversed(range(0, len(inter_path))):
if isinstance(inter_path[i], CardADF):
return inter_path[i:]
return inter_path
"""Build the relative sequence of files we need to traverse to get from us to 'target'."""
# special-case handling for selecting MF while we MF is selected
if target == target.get_mf():
@ -152,7 +162,7 @@ class CardFile:
for te2 in target_fqpath[i+1:]:
inter_path.append(te2)
# we found our common ancestor
return inter_path[1:]
return clip_path(inter_path[1:])
return None
def get_mf(self) -> Optional['CardMF']: