Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:adb push fail #1271

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions airtest/core/android/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,25 +494,23 @@ def push(self, local, remote):
>>> adb.push("test_dir", "/sdcard/Android/data/com.test.package/files/test_dir")

"""
_, ext = os.path.splitext(remote)
if ext:
# The target path is a file
if os.path.isfile(local):
# The local path is a file
dst_parent = os.path.dirname(remote)
else:
dst_parent = remote

# If the target file already exists, delete it first to avoid overwrite failure
src_filename = os.path.basename(local)
_, src_ext = os.path.splitext(local)
if src_ext:
if os.path.isfile(local):
dst_path = f"{dst_parent}/{src_filename}"
else:
if src_filename == os.path.basename(remote):
dst_path = remote
else:
dst_path = f"{dst_parent}/{src_filename}"
try:
self.shell(f"rm -r {dst_path}")
self.shell(f"rm -r {remote}")
except:
pass

Expand All @@ -530,14 +528,11 @@ def push(self, local, remote):
self.cmd(["push", local, dst_parent])
else:
try:
if src_ext:
try:
self.shell(f'mv "{tmp_path}" "{remote}"')
except:
self.shell(f'mv "{tmp_path}" "{remote}"')
if os.path.isfile(local):
self.shell(f'mv "{tmp_path}" "{remote}"')
else:
try:
self.shell(f'cp -frp "{tmp_path}/*" "{remote}"')
self.shell(f'cp -frp {tmp_path}/* {remote}')
except:
self.shell(f'mv "{tmp_path}" "{remote}"')
finally:
Expand Down
Loading