pySim-shell: prevent inconsitancy when walking through the FS tree

When using the method walk() to walk through the filesystem tree, then
the action() callback must not change the currently selected file.
Unfortunately this can easily happen and result in unpredictable
behavior. Lets add a check + an exeception for this to make debugging
easier.

Change-Id: I6778faa87bdf5552da74659206bf7a6fc0348d0c
Related: OS#4963
This commit is contained in:
Philipp Maier 2021-04-01 17:13:03 +02:00 committed by Harald Welte
parent 46f09af11d
commit b152a9e0ed
1 changed files with 7 additions and 0 deletions

View File

@ -263,7 +263,14 @@ class Iso7816Commands(CommandSet):
self.walk(indent + 1, action, context)
fcp_dec = self._cmd.rs.select("..", self._cmd)
elif action:
df_before_action = self._cmd.rs.selected_file
action(f, context)
# When walking through the file system tree the action must not
# always restore the currently selected file to the file that
# was selected before executing the action() callback.
if df_before_action != self._cmd.rs.selected_file:
raise RuntimeError("inconsistant walk, %s is currently selected but expecting %s to be selected"
% (str(self._cmd.rs.selected_file), str(df_before_action)))
def do_tree(self, opts):
"""Display a filesystem-tree with all selectable files"""