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

"file" command in afc shell appears to run on host instead of inside device #1196

Open
ViRb3 opened this issue Sep 11, 2024 · 4 comments
Open

Comments

@ViRb3
Copy link

ViRb3 commented Sep 11, 2024

Test environment

  • Host OS version: macOS 14.6.1
  • Target device model and iOS version: iPhone 15 Pro, iOS 17.6.1

Describe the bug
I'm trying to run the file command to see information about a file on my device. However, I always get an error that the file does not exist. If I use tab auto-complete, I get suggestions for files in the current working directory of my host, not my iDevice. Surely enough, it also executes file if I specify a file on my host.

To Reproduce

pymobiledevice3 apps afc com.example.app
file example.txt

Expected behavior
Result from device is returned

Logs
Result from host is returned instead

Additional context
N/A

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@doronz88
Copy link
Owner

Yeah that's because the provided shell isn't a real shell but a mock instead. pmd defines aliases to make it work with connected device, but when u run any other command that isn't mapped as an alias, it runs on your local machine instead. If you want, you can add an implementaion for file which reads the file from the device, and then executes the file command`

@ViRb3
Copy link
Author

ViRb3 commented Sep 11, 2024

Ah, I figured that's what happens, but I noticed that file is in the available commands from show-help. I assumed that list comes from AFC itself, so maybe a mapping/alias is just missing?

@ViRb3
Copy link
Author

ViRb3 commented Sep 11, 2024

Found the relevant code, seems like this is there for a reason:

def _setup_shell_commands(self):
# clear all host commands except for some useful ones
XSH.env['PATH'].clear()
# adding "file" just to fix xonsh errors
for cmd in ['wc', 'grep', 'egrep', 'sed', 'awk', 'print', 'yes', 'cat', 'file']:
executable = shutil.which(cmd)
if executable is not None:
self._register_rpc_command(cmd, executable)

@doronz88
Copy link
Owner

Created this on xonsh repo:

xonsh/xonsh#5683

If this issue is resolved, I can remove the file hack.
It was just there so it won't break the shell.

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

No branches or pull requests

2 participants