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

Unified Diff: build/android/pylib/utils/device_temp_file.py

Issue 773043005: Revert of Allow RunShellCommand to work even with very large commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 | « build/android/pylib/device/device_utils_test.py ('k') | build/android/pylib/utils/device_temp_file_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/utils/device_temp_file.py
diff --git a/build/android/pylib/utils/device_temp_file.py b/build/android/pylib/utils/device_temp_file.py
index ba95395d8b525d320c1172844ca5bce44b700e99..2a9b45101803e18f2ca8046a25e8bb126e5624b4 100644
--- a/build/android/pylib/utils/device_temp_file.py
+++ b/build/android/pylib/utils/device_temp_file.py
@@ -9,42 +9,34 @@
import random
import time
-from pylib import cmd_helper
-from pylib.device import device_errors
-
-
class DeviceTempFile(object):
- def __init__(self, adb, prefix='temp_file', suffix=''):
+ def __init__(self, device, prefix='temp_file', suffix=''):
"""Find an unused temporary file path in the devices external directory.
When this object is closed, the file will be deleted on the device.
Args:
- adb: An instance of AdbWrapper
+ device: An instance of DeviceUtils
prefix: The prefix of the name of the temp file.
suffix: The suffix of the name of the temp file.
"""
- self._adb = adb
- external_storage = self._adb.Shell('echo $EXTERNAL_STORAGE').rstrip()
- # make sure that external storage is readable
- self._adb.Shell('test -d %s' % external_storage)
+ self._device = device
while True:
- self.name = '{path}/{prefix}-{time:d}-{nonce:d}{suffix}'.format(
- path=external_storage, prefix=prefix, time=int(time.time()),
- nonce=random.randint(0, 1000000), suffix=suffix)
- self.name_quoted = cmd_helper.SingleQuote(self.name)
- try:
- self._adb.Shell('test -e %s' % self.name_quoted)
- except device_errors.AdbCommandFailedError:
- break # file does not exist
-
- # Immediately touch the file, so other temp files can't get the same name.
- self._adb.Shell('touch %s' % self.name_quoted)
+ i = random.randint(0, 1000000)
+ self.name = '%s/%s-%d-%010d%s' % (
+ self._device.GetExternalStoragePath(),
+ prefix, int(time.time()), i, suffix)
+ if not self._device.FileExists(self.name):
+ break
+ # Immediately create an empty file so that other temp files can't
+ # be given the same name.
+ # |as_root| must be set to False due to the implementation of |WriteFile|.
+ # Having |as_root| be True may cause infinite recursion.
+ self._device.WriteFile(self.name, '', as_root=False)
def close(self):
"""Deletes the temporary file from the device."""
- # we use -f to ignore errors if the file is already gone
- self._adb.Shell('rm -f %s' % self.name_quoted)
+ self._device.RunShellCommand(['rm', self.name])
def __enter__(self):
return self
« no previous file with comments | « build/android/pylib/device/device_utils_test.py ('k') | build/android/pylib/utils/device_temp_file_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698