diff options
| author | Damien George <damien@micropython.org> | 2024-09-27 12:37:18 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-10-09 16:39:06 +1100 |
| commit | a25b6b9c65a587f534f802f821b30972de29e2af (patch) | |
| tree | e45aa252b8ea2abc2fc3fd16ef93907edcd07aa3 | |
| parent | 6461ffd9d174fdf799c8de27f92e4505ec731c7e (diff) | |
tools/mpremote: Add option to force copy.
This adds a -f/--force option to the "cp" command, which forces
unconditional copies, in particular does not check the hash.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | tools/mpremote/mpremote/commands.py | 12 | ||||
| -rw-r--r-- | tools/mpremote/mpremote/main.py | 7 |
2 files changed, 14 insertions, 5 deletions
diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 1f3a89a84..2b1acea43 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -184,7 +184,7 @@ def do_filesystem_cp(state, src, dest, multiple, check_hash=False): f.write(data) -def do_filesystem_recursive_cp(state, src, dest, multiple): +def do_filesystem_recursive_cp(state, src, dest, multiple, check_hash): # Ignore trailing / on both src and dest. (Unix cp ignores them too) src = src.rstrip("/" + os.path.sep + (os.path.altsep if os.path.altsep else "")) dest = dest.rstrip("/" + os.path.sep + (os.path.altsep if os.path.altsep else "")) @@ -257,7 +257,7 @@ def do_filesystem_recursive_cp(state, src, dest, multiple): # If no directories were encountered then we must have just had a file. if not dirs: - return do_filesystem_cp(state, src, dest, multiple) + return do_filesystem_cp(state, src, dest, multiple, check_hash) def _mkdir(a, *b): try: @@ -287,7 +287,7 @@ def do_filesystem_recursive_cp(state, src, dest, multiple): else: dest_path_joined = os.path.join(dest, *dest_path_split) - do_filesystem_cp(state, src_path_joined, dest_path_joined, multiple=False, check_hash=True) + do_filesystem_cp(state, src_path_joined, dest_path_joined, False, check_hash) def do_filesystem(state, args): @@ -352,9 +352,11 @@ def do_filesystem(state, args): print(digest.hex()) elif command == "cp": if args.recursive: - do_filesystem_recursive_cp(state, path, cp_dest, len(paths) > 1) + do_filesystem_recursive_cp( + state, path, cp_dest, len(paths) > 1, not args.force + ) else: - do_filesystem_cp(state, path, cp_dest, len(paths) > 1) + do_filesystem_cp(state, path, cp_dest, len(paths) > 1, not args.force) except FileNotFoundError as er: raise CommandError("{}: {}: No such file or directory.".format(command, er.args[0])) except IsADirectoryError as er: diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index c5e73b1cc..8c0a6cd22 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -184,6 +184,13 @@ def argparse_filesystem(): _bool_flag(cmd_parser, "recursive", "r", False, "recursive copy (for cp command only)") _bool_flag( cmd_parser, + "force", + "f", + False, + "force copy even if file is unchanged (for cp command only)", + ) + _bool_flag( + cmd_parser, "verbose", "v", None, |
