<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/23568">View Change</a></p><div style="white-space:pre-wrap">Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pySim-shell: fix and improve file system exporter<br><br>The file system exporter function export() selects the exported EF from<br>inside a try block. It also selects the parent DF again when leaving the<br>try block. If an exception ocurrs during select this is fine, but if it<br>happens during read it leaves the EF selected which makes messes up the<br>recursive filesystem walk.<br><br>There are also minor inconsistancies with the exception strings and the<br>path displayed in the execption strings<br><br>Related: OS#4963<br>Change-Id: Ie9b1712b37e5b39e9016497185510a2a45c4ca6c<br>---<br>M pySim-shell.py<br>1 file changed, 20 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim-shell.py b/pySim-shell.py</span><br><span>index 2ac0b26..3c56f51 100755</span><br><span>--- a/pySim-shell.py</span><br><span>+++ b/pySim-shell.py</span><br><span>@@ -277,28 +277,33 @@</span><br><span> self.walk()</span><br><span> </span><br><span> def export(self, filename, context):</span><br><span style="color: hsl(120, 100%, 40%);">+ """ Select and export a single file """</span><br><span> context['COUNT'] += 1</span><br><span style="color: hsl(0, 100%, 40%);">- path_list = self._cmd.rs.selected_file.fully_qualified_path(True)</span><br><span style="color: hsl(0, 100%, 40%);">- path_list_fid = self._cmd.rs.selected_file.fully_qualified_path(False)</span><br><span style="color: hsl(120, 100%, 40%);">+ df = self._cmd.rs.selected_file</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if not isinstance(df, CardDF):</span><br><span style="color: hsl(120, 100%, 40%);">+ raise RuntimeError("currently selected file %s is not a DF or ADF" % str(df))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ df_path_list = df.fully_qualified_path(True)</span><br><span style="color: hsl(120, 100%, 40%);">+ df_path_list_fid = df.fully_qualified_path(False)</span><br><span> </span><br><span> self._cmd.poutput("#" * 80)</span><br><span style="color: hsl(0, 100%, 40%);">- file_str = '/'.join(path_list) + "/" + str(filename) + " " * 80</span><br><span style="color: hsl(120, 100%, 40%);">+ file_str = '/'.join(df_path_list) + "/" + str(filename) + " " * 80</span><br><span> self._cmd.poutput("# " + file_str[0:77] + "#")</span><br><span> self._cmd.poutput("#" * 80)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- self._cmd.poutput("# directory: %s (%s)" % ('/'.join(path_list), '/'.join(path_list_fid)))</span><br><span style="color: hsl(120, 100%, 40%);">+ self._cmd.poutput("# directory: %s (%s)" % ('/'.join(df_path_list), '/'.join(df_path_list_fid)))</span><br><span> try:</span><br><span> fcp_dec = self._cmd.rs.select(filename, self._cmd)</span><br><span style="color: hsl(0, 100%, 40%);">- path_list = self._cmd.rs.selected_file.fully_qualified_path(True)</span><br><span style="color: hsl(0, 100%, 40%);">- path_list_fid = self._cmd.rs.selected_file.fully_qualified_path(False)</span><br><span style="color: hsl(0, 100%, 40%);">- self._cmd.poutput("# file: %s (%s)" % (path_list[-1], path_list_fid[-1]))</span><br><span style="color: hsl(120, 100%, 40%);">+ self._cmd.poutput("# file: %s (%s)" % (self._cmd.rs.selected_file.name, self._cmd.rs.selected_file.fid))</span><br><span> </span><br><span> fd = fcp_dec['file_descriptor']</span><br><span> structure = fd['structure']</span><br><span> self._cmd.poutput("# structure: %s" % str(structure))</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for f in path_list:</span><br><span style="color: hsl(120, 100%, 40%);">+ for f in df_path_list:</span><br><span> self._cmd.poutput("select " + str(f))</span><br><span style="color: hsl(120, 100%, 40%);">+ self._cmd.poutput("select " + self._cmd.rs.selected_file.name)</span><br><span> </span><br><span> if structure == 'transparent':</span><br><span> result = self._cmd.rs.read_binary()</span><br><span>@@ -308,13 +313,18 @@</span><br><span> for r in range(1, num_of_rec + 1):</span><br><span> result = self._cmd.rs.read_record(r)</span><br><span> self._cmd.poutput("update_record %d %s" % (r, str(result[0])))</span><br><span style="color: hsl(0, 100%, 40%);">- fcp_dec = self._cmd.rs.select("..", self._cmd)</span><br><span> except Exception as e:</span><br><span style="color: hsl(0, 100%, 40%);">- bad_file_str = '/'.join(path_list) + "/" + str(filename) + ", " + str(e)</span><br><span style="color: hsl(120, 100%, 40%);">+ bad_file_str = '/'.join(df_path_list) + "/" + str(filename) + ", " + str(e)</span><br><span> self._cmd.poutput("# bad file: %s" % bad_file_str)</span><br><span> context['ERR'] += 1</span><br><span> context['BAD'].append(bad_file_str)</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ # When reading the file is done, make sure the parent file is</span><br><span style="color: hsl(120, 100%, 40%);">+ # selected again. This will be the usual case, however we need</span><br><span style="color: hsl(120, 100%, 40%);">+ # to check before since we must not select the same DF twice</span><br><span style="color: hsl(120, 100%, 40%);">+ if df != self._cmd.rs.selected_file:</span><br><span style="color: hsl(120, 100%, 40%);">+ self._cmd.rs.select(df.fid or df.aid, self._cmd)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> self._cmd.poutput("#")</span><br><span> </span><br><span> export_parser = argparse.ArgumentParser()</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/23568">change 23568</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/23568"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ie9b1712b37e5b39e9016497185510a2a45c4ca6c </div>
<div style="display:none"> Gerrit-Change-Number: 23568 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>