Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: devil/devil/android/device_utils.py

Issue 1585243002: [devil] Add as_root option to DeviceUtils.PathExists. (Closed) Base URL: git@github.com:catapult-project/catapult.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | devil/devil/android/device_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: devil/devil/android/device_utils.py
diff --git a/devil/devil/android/device_utils.py b/devil/devil/android/device_utils.py
index 05f3181b494d2fbcd47e2e48ae7619b7961dc3e2..bd556ba3d69d6df241b155810d53ce84cdae326c 100644
--- a/devil/devil/android/device_utils.py
+++ b/devil/devil/android/device_utils.py
@@ -1367,12 +1367,14 @@ class DeviceUtils(object):
"""
return self.PathExists(device_path, timeout=timeout, retries=retries)
- def PathExists(self, device_paths, timeout=None, retries=None):
+ def PathExists(self, device_paths, as_root=False, timeout=None, retries=None):
"""Checks whether the given path(s) exists on the device.
Args:
device_path: A string containing the absolute path to the file on the
device, or an iterable of paths to check.
+ as_root: Whether root permissions should be use to check for the existence
+ of the given path(s).
timeout: timeout in seconds
retries: number of retries
@@ -1387,10 +1389,13 @@ class DeviceUtils(object):
if isinstance(paths, basestring):
paths = (paths,)
condition = ' -a '.join('-e %s' % cmd_helper.SingleQuote(p) for p in paths)
- cmd = 'test %s;echo $?' % condition
- result = self.RunShellCommand(cmd, check_return=True, timeout=timeout,
- retries=retries)
- return '0' == result[0]
+ cmd = 'test %s' % condition
+ try:
+ self.RunShellCommand(cmd, as_root=as_root, check_return=True,
+ timeout=timeout, retries=retries)
+ return True
+ except device_errors.CommandFailedError:
+ return False
@decorators.WithTimeoutAndRetriesFromInstance()
def PullFile(self, device_path, host_path, timeout=None, retries=None):
« no previous file with comments | « no previous file | devil/devil/android/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698