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>
This commit is contained in:
parent
6461ffd9d1
commit
a25b6b9c65
2 changed files with 14 additions and 5 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -182,6 +182,13 @@ 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,
|
||||
"force",
|
||||
"f",
|
||||
False,
|
||||
"force copy even if file is unchanged (for cp command only)",
|
||||
)
|
||||
_bool_flag(
|
||||
cmd_parser,
|
||||
"verbose",
|
||||
|
|
|
|||
Loading…
Reference in a new issue