filesystem: add command to delete all contents from a BER-TLV EF

When working with BER-TLF files, we can only delete one tag at a time.
There is no way to delete all tags at once. This may make working with
BER-TLV files difficult, in particular when scripting is used and the
script needs to start with an empty file. Also export has problems,
since it does not reset the file before setting the new values there
may be unexpected results in case there still tags in the file that
are not set during import. To fill the gap, let's add a commandd that
deletes all tags in a BER-TLV EF at once.

Related: OS#6531
Change-Id: I5d6bcfe865df7cb8fa6dd0052cab3b364d929f94
This commit is contained in:
Philipp Maier
2024-08-23 12:25:54 +02:00
parent d20be98ed1
commit edf266726d

View File

@@ -1338,6 +1338,12 @@ class BerTlvEF(CardEF):
if data:
self._cmd.poutput(data)
def do_delete_all(self, opts):
"""Delete all data from a BER-TLV EF"""
tags = self._cmd.lchan.retrieve_tags()
for tag in tags:
self._cmd.lchan.set_data(tag, None)
def __init__(self, fid: str, sfid: str = None, name: str = None, desc: str = None, parent: CardDF = None,
size: Size = (1, None), **kwargs):
"""
@@ -1374,6 +1380,7 @@ class BerTlvEF(CardEF):
if tags == []:
export_str += "# empty file, no tags"
else:
export_str += "delete_all\n"
for t in tags:
result = lchan.retrieve_data(t)
(tag, l, val, remainer) = bertlv_parse_one(h2b(result[0]))