diff options
| author | Damien George <damien@micropython.org> | 2024-11-06 12:45:06 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-11-13 11:51:35 +1100 |
| commit | 4fd5b72a8b71c6b3a074bcc3b9f6385b049c3dcb (patch) | |
| tree | 8875e1e0bf33ff43a1b54c7ba9f721302b002b01 | |
| parent | 3b6024a699491720ac0ba48b8534d6e540e828a9 (diff) | |
tools/mpremote: Support trailing slash on dest for non-recursive copy.
This fixes a regression in db59e55fe7a0b67d3af868990468e7b8056afe42: prior
to that commit `mpremote` supported trailing slashes on the destination of
a normal (non-recursive) copy.
Add back support for that, with the semantics that a trailing slash
requires the destination to be an existing directory.
Also add a test for this.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | tools/mpremote/mpremote/commands.py | 11 | ||||
| -rwxr-xr-x | tools/mpremote/tests/test_filesystem.sh | 5 | ||||
| -rw-r--r-- | tools/mpremote/tests/test_filesystem.sh.exp | 6 |
3 files changed, 20 insertions, 2 deletions
diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 2b1acea43..f86befd08 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -129,8 +129,15 @@ def _remote_path_basename(a): def do_filesystem_cp(state, src, dest, multiple, check_hash=False): if dest.startswith(":"): - dest_exists = state.transport.fs_exists(dest[1:]) - dest_isdir = dest_exists and state.transport.fs_isdir(dest[1:]) + dest_no_slash = dest.rstrip("/" + os.path.sep + (os.path.altsep or "")) + dest_exists = state.transport.fs_exists(dest_no_slash[1:]) + dest_isdir = dest_exists and state.transport.fs_isdir(dest_no_slash[1:]) + + # A trailing / on dest forces it to be a directory. + if dest != dest_no_slash: + if not dest_isdir: + raise CommandError("cp: destination is not a directory") + dest = dest_no_slash else: dest_exists = os.path.exists(dest) dest_isdir = dest_exists and os.path.isdir(dest) diff --git a/tools/mpremote/tests/test_filesystem.sh b/tools/mpremote/tests/test_filesystem.sh index 727efea90..afeb7c91d 100755 --- a/tools/mpremote/tests/test_filesystem.sh +++ b/tools/mpremote/tests/test_filesystem.sh @@ -71,6 +71,11 @@ echo ----- $MPREMOTE resume cp -f "${TMP}/a.py" :aaa $MPREMOTE resume cat :aaa/a.py +# Test cp where the destination has a trailing /. +echo ----- +$MPREMOTE resume cp "${TMP}/a.py" :aaa/ +$MPREMOTE resume cp "${TMP}/a.py" :aaa/a.py/ || echo "expect error" + echo ----- $MPREMOTE resume rm :b.py c.py $MPREMOTE resume ls diff --git a/tools/mpremote/tests/test_filesystem.sh.exp b/tools/mpremote/tests/test_filesystem.sh.exp index b252bc7eb..82fe7d6bf 100644 --- a/tools/mpremote/tests/test_filesystem.sh.exp +++ b/tools/mpremote/tests/test_filesystem.sh.exp @@ -42,6 +42,12 @@ cp ${TMP}/a.py :aaa print("Hello") print("World") ----- +cp ${TMP}/a.py :aaa/ +Up to date: aaa/a.py +cp ${TMP}/a.py :aaa/a.py/ +mpremote: cp: destination is not a directory +expect error +----- rm :b.py rm :c.py ls : |
