From b152a9e0edec37518ce372ca5f5a61e440070d75 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Thu, 1 Apr 2021 17:13:03 +0200 Subject: [PATCH] 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 --- pySim-shell.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pySim-shell.py b/pySim-shell.py index 11953eb0..2ac0b265 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -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"""