8000 tools/mpremote: Add option to force copy. · micropython/micropython@a25b6b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit a25b6b9

Browse files
committed
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>
1 parent 6461ffd commit a25b6b9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

tools/mpremote/mpremote/commands.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def do_filesystem_cp(state, src, dest, multiple, check_hash=False):
184184
f.write(data)
185185

186186

187-
def do_filesystem_recursive_cp(state, src, dest, multiple):
187+
def do_filesystem_recursive_cp(state, src, dest, multiple, check_hash):
188188
# Ignore trailing / on both src and dest. (Unix cp ignores them too)
189189
src = src.rstrip("/" + os.path.sep + (os.path.altsep if os.path.altsep else ""))
190190
dest = dest.rstrip("/" + os.path.sep + (os.path.altsep if os.path.altsep else ""))
@@ -257,7 +257,7 @@ def _list_recursive(base, src_path, dest_path, src_join_fun, src_isdir_fun, src_
257257

258258
# If no directories were encountered then we must have just had a file.
259259
if not dirs:
260-
return do_filesystem_cp(state, src, dest, multiple)
260+
return do_filesystem_cp(state, src, dest, multiple, check_hash)
261261

262262
def _mkdir(a, *b):
263263
try:
@@ -287,7 +287,7 @@ def _mkdir(a, *b):
287287
else:
288288
dest_path_joined = os.path.join(dest, *dest_path_split)
289289

290-
do_filesystem_cp(state, src_path_joined, dest_path_joined, multiple=False, check_hash=True)
290+
do_filesystem_cp(state, src_path_joined, dest_path_joined, False, check_hash)
291291

292292

293293
def do_filesystem(state, args):
@@ -352,9 +352,11 @@ def do_filesystem(state, args):
352352
print(digest.hex())
353353
elif command == "cp":
354354
if args.recursive:
355-
do_filesystem_recursive_cp(state, path, cp_dest, len(paths) > 1)
355+
do_filesystem_recursive_cp(
356+
state, path, cp_dest, len(paths) > 1, not args.force
357+
)
356358
else:
357-
do_filesystem_cp(state, path, cp_dest, len(paths) > 1)
359+
do_filesystem_cp(state, path, cp_dest, len(paths) > 1, not args.force)
358360
except FileNotFoundError as er:
359361
raise CommandError("{}: {}: No such file or directory.".format(command, er.args[0]))
360362
except IsADirectoryError as er:

tools/mpremote/mpremote/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ def argparse_rtc():
182182
def argparse_filesystem():
183183
cmd_parser = argparse.ArgumentParser(description="execute filesystem commands on the device")
184184
_bool_flag(cmd_parser, "recursive", "r", False, "recursive copy (for cp command only)")
185+
_bool_flag(
186+
cmd_parser,
187+
"force",
188+
"f",
189+
False,
190+
"force copy even if file is unchanged (for cp command only)",
191+
)
185192
_bool_flag(
186193
cmd_parser,
187194
"verbose",

0 commit comments

Comments
 (0)
0