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:
@@ -184,7 +184,7 @@ def do_filesystem_cp(state, src, dest, multiple, check_hash=False):
|
|||||||
f.write(data)
|
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)
|
# 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 ""))
|
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 ""))
|
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 no directories were encountered then we must have just had a file.
|
||||||
if not dirs:
|
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):
|
def _mkdir(a, *b):
|
||||||
try:
|
try:
|
||||||
@@ -287,7 +287,7 @@ def do_filesystem_recursive_cp(state, src, dest, multiple):
|
|||||||
else:
|
else:
|
||||||
dest_path_joined = os.path.join(dest, *dest_path_split)
|
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):
|
def do_filesystem(state, args):
|
||||||
@@ -352,9 +352,11 @@ def do_filesystem(state, args):
|
|||||||
print(digest.hex())
|
print(digest.hex())
|
||||||
elif command == "cp":
|
elif command == "cp":
|
||||||
if args.recursive:
|
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:
|
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:
|
except FileNotFoundError as er:
|
||||||
raise CommandError("{}: {}: No such file or directory.".format(command, er.args[0]))
|
raise CommandError("{}: {}: No such file or directory.".format(command, er.args[0]))
|
||||||
except IsADirectoryError as er:
|
except IsADirectoryError as er:
|
||||||
|
|||||||
@@ -182,6 +182,13 @@ def argparse_rtc():
|
|||||||
def argparse_filesystem():
|
def argparse_filesystem():
|
||||||
cmd_parser = argparse.ArgumentParser(description="execute filesystem commands on the device")
|
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 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(
|
_bool_flag(
|
||||||
cmd_parser,
|
cmd_parser,
|
||||||
"verbose",
|
"verbose",
|
||||||
|
|||||||
Reference in New Issue
Block a user