Skip to content

fix: preserve ADB push destination paths - #1329

Open
BruceWae wants to merge 2 commits into
AirtestProject:masterfrom
BruceWae:fix/adb-push-path-detection
Open

BruceWae wants to merge 2 commits into
AirtestProject:masterfrom
BruceWae:fix/adb-push-path-detection

Conversation

@BruceWae

Copy link
Copy Markdown

Summary

  • Determine ADB push destinations from the local source type.
  • Preserve extensionless file names and directories containing dots.
  • Add regression tests for both path handling cases.

Fixes

Fixes #1321.

The previous implementation inspected the remote Android path with local os.path.isfile() and used its extension to decide whether the destination was a file or directory. That could route files and directories to incorrect paths. The updated implementation derives the destination from the local source and uses the computed destination consistently for temporary transfers.

Testing

  • python -m unittest tests.test_adb.TestADBWithoutDevice.test_push_extensionless_file_to_renamed_remote_path tests.test_adb.TestADBWithoutDevice.test_push_directory_to_remote_path_containing_dot -v
  • python -m compileall -q airtest tests
  • git diff --check

Determine the destination from the local source type instead of parsing the remote Android path. This keeps extensionless files and directories with dots from being routed to the wrong location, and adds regression coverage for both cases.
Copilot AI lite review requested due to automatic review settings August 12, 2026 03:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates ADB.push() path resolution to avoid misclassifying remote destinations based on filename extensions (especially for extensionless files and dot-containing paths), and adds regression tests for the updated behavior.

Changes:

  • Reworked airtest.core.android.adb.ADB.push() to derive and consistently use a computed dst_path for cleanup, mkdir, temporary push, and final placement.
  • Updated temp-transfer logic to use the computed destination basename for staging.
  • Added unit tests covering extensionless-file rename and directory push into a dot-containing remote path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airtest/core/android/adb.py Adjusts ADB.push() destination computation and temp-transfer behavior to preserve intended remote paths.
tests/test_adb.py Adds regression tests for extensionless file destination preservation and dot-containing remote path handling.
Suppressed comments (1)

airtest/core/android/adb.py:532

  • When dst_path is already inside TMP_PATH (common when remote is "/data/local/tmp"), tmp_path becomes equal to dst_path. In the directory case, the subsequent cp -frp "tmp_path" "dst_parent" attempts to copy a directory into its own parent (or into itself), which can error or create unintended nested paths. Adding a fast-path when tmp_path == dst_path avoids this and also lets you simplify the redundant mv try/except.
        tmp_path = f"{TMP_PATH}/{os.path.basename(dst_path)}"
        try:
            self.cmd(["push", local, tmp_path])
        except:
            self.cmd(["push", local, dst_path])

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +499 to +507
if src_is_file:
# A remote path without an extension is still a file when the
# local source is a file and the caller supplied a new name.
src_ext = os.path.splitext(local)[-1]
dst_ext = os.path.splitext(remote)[-1]
if dst_ext == "" and src_ext != "":
dst_path = f"{remote}/{os.path.basename(local)}"
else:
dst_path = remote
Comment on lines 515 to 525
try:
self.shell(f"rm -r {dst_path}")
except:
pass

# If the target folder has multiple levels that have never been created, try to create them
dst_parent = os.path.dirname(dst_path)
try:
self.shell(f"mkdir -p {dst_parent}")
except:
pass
Handle trailing-slash destinations for extensionless files and pass remote paths as separate adb shell arguments. Add regression coverage for directory-style destinations while addressing the review feedback on path handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ADB.push() misresolves file/directory by extension, breaking minicap install

2 participants