diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/mpremote/mpremote/commands.py | 28 | ||||
| -rw-r--r-- | tools/mpremote/mpremote/main.py | 2 | ||||
| -rw-r--r-- | tools/mpremote/mpremote/transport.py | 6 |
3 files changed, 33 insertions, 3 deletions
diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index e385d0509..690b2ea72 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -1,4 +1,5 @@ import binascii +import errno import hashlib import os import sys @@ -300,6 +301,28 @@ def do_filesystem_recursive_cp(state, src, dest, multiple, check_hash): do_filesystem_cp(state, src_path_joined, dest_path_joined, False, check_hash) +def do_filesystem_recursive_rm(state, path, args): + if state.transport.fs_isdir(path): + for entry in state.transport.fs_listdir(path): + do_filesystem_recursive_rm(state, _remote_path_join(path, entry.name), args) + if path: + try: + state.transport.fs_rmdir(path) + if args.verbose: + print(f"removed directory: '{path}'") + except OSError as e: + if e.errno != errno.EINVAL: # not vfs mountpoint + raise CommandError( + f"rm -r: cannot remove :{path} {os.strerror(e.errno) if e.errno else ''}" + ) from e + if args.verbose: + print(f"skipped: '{path}' (vfs mountpoint)") + else: + state.transport.fs_rmfile(path) + if args.verbose: + print(f"removed: '{path}'") + + def do_filesystem(state, args): state.ensure_raw_repl() state.did_action() @@ -352,7 +375,10 @@ def do_filesystem(state, args): elif command == "mkdir": state.transport.fs_mkdir(path) elif command == "rm": - state.transport.fs_rmfile(path) + if args.recursive: + do_filesystem_recursive_rm(state, path, args) + else: + state.transport.fs_rmfile(path) elif command == "rmdir": state.transport.fs_rmdir(path) elif command == "touch": diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index bdae8f163..b30a1a213 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -182,7 +182,7 @@ def argparse_rtc(): def argparse_filesystem(): cmd_parser = argparse.ArgumentParser(description="execute filesystem commands on the device") - _bool_flag(cmd_parser, "recursive", "r", False, "recursive copy (for cp command only)") + _bool_flag(cmd_parser, "recursive", "r", False, "recursive (for cp and rm commands)") _bool_flag( cmd_parser, "force", diff --git a/tools/mpremote/mpremote/transport.py b/tools/mpremote/mpremote/transport.py index c8fdc54a8..8d30c7f51 100644 --- a/tools/mpremote/mpremote/transport.py +++ b/tools/mpremote/mpremote/transport.py @@ -24,7 +24,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -import ast, hashlib, os, sys +import ast, errno, hashlib, os, sys from collections import namedtuple @@ -63,6 +63,10 @@ def _convert_filesystem_error(e, info): return FileExistsError(info) if "OSError" in e.error_output and "ENODEV" in e.error_output: return FileNotFoundError(info) + if "OSError" in e.error_output and "EINVAL" in e.error_output: + return OSError(errno.EINVAL, info) + if "OSError" in e.error_output and "EPERM" in e.error_output: + return OSError(errno.EPERM, info) return e |
