summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-11-06 12:45:06 +1100
committerDamien George <damien@micropython.org>2024-11-18 23:27:13 +1100
commit4e78c611b4b2ac2ee9eefb90b352fdc585f2a80a (patch)
tree913ba535bbbd2de173605d46e118d04d81d954b6
parent159b54b7da404bc9a8d60d8c989e33e11412e548 (diff)
downloadmicropython-4e78c611b4b2ac2ee9eefb90b352fdc585f2a80a.tar.gz
micropython-4e78c611b4b2ac2ee9eefb90b352fdc585f2a80a.zip
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.py11
-rwxr-xr-xtools/mpremote/tests/test_filesystem.sh5
-rw-r--r--tools/mpremote/tests/test_filesystem.sh.exp6
3 files changed, 20 insertions, 2 deletions
diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py
index 2b1acea438..f86befd080 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 727efea90e..afeb7c91da 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 b252bc7eb0..82fe7d6bf7 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 :