Solve 'stat' command not available on some devices #163
+14
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As 'stat' command might be not available, I tried to use 'ls -l's output instead.
I used bellow script to test the new method:
from uiautomator2 import adbutils
import os
adb = adbutils.Adb('4840a1ba')
dirs = ['/data/local/tmp', '/data/data/com.android.shell', '/data', '/data/local']
for dirname in dirs:
testpath = "%s/%s" % (dirname, 'permtest')
adb.shell('touch', testpath, raise_error=False)
adb.shell('chmod', '+x', testpath, raise_error=False)
content = adb.shell('ls', '-l', testpath, raise_error=False)
print('ls output: "%s"' % content)
if -1 !=content.find('x'):
print(dirname, 'is executable')
else:
print(dirname, 'is not executable')
Result1 from Z2
ls output: "-rw-rw-rw- shell shell 0 2018-07-11 19:41 permtest
"
/data/local/tmp is not executable
ls output: "-rwxrwxrwx shell shell 0 2018-07-11 19:41 permtest
"
/data/data/com.android.shell is executable
ls output: "/data/permtest: No such file or directory
"
/data is not executable
ls output: "/data/local/permtest: No such file or directory
"
/data/local is not executable
Result2 from Samsung S7 edge
ls output: "-rwxrwxrwx 1 shell shell 0 2018-07-11 19:42 /data/local/tmp/permtest
"
/data/local/tmp is executable
ls output: "-rwxrwxrwx 1 shell shell 0 2018-07-11 19:42 /data/data/com.android.shell/permtest
"
/data/data/com.android.shell is executable
ls output: ""
/data is not executable
ls output: ""
/data/local is not executable