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

Unified Diff: build/android/pylib/android_commands.py

Issue 270833004: Android: Make sure temporary scripts are deleted from the device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/android_commands.py
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py
index 0a710f9e0ef2cc237996c360940df8265a927f01..db71d6d341a44e8af9dbe6026f534002c837e5b3 100644
--- a/build/android/pylib/android_commands.py
+++ b/build/android/pylib/android_commands.py
@@ -1160,25 +1160,33 @@ class AndroidCommands(object):
This is less efficient than SetFileContents.
"""
+ # TODO(skyostil): Remove this once it has been through all the bots.
jbudorick 2014/05/08 15:37:25 I'm not sure I like this idea, but I suppose this
Sami 2014/05/08 15:57:11 Yeah, AFAIK we don't have any easy way to run thes
Yaron 2014/05/08 17:08:16 I think it's the easiest way to clean up the curre
+ for file_name in (AndroidCommands._TEMP_FILE_BASE_FMT,
+ AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT):
+ self.RunShellCommand('rm ' + self.GetExternalStorage() + '/' +
+ file_name.replace('%d', '*'))
+
temp_file = self._GetDeviceTempFileName(AndroidCommands._TEMP_FILE_BASE_FMT)
temp_script = self._GetDeviceTempFileName(
AndroidCommands._TEMP_SCRIPT_FILE_BASE_FMT)
- # Put the contents in a temporary file
- self.SetFileContents(temp_file, contents)
- # Create a script to copy the file contents to its final destination
- self.SetFileContents(temp_script, 'cat %s > %s' % (temp_file, filename))
-
- command = 'sh %s' % temp_script
- command_runner = self._GetProtectedFileCommandRunner()
- if command_runner:
- return command_runner(command)
- else:
- logging.warning('Could not set contents of protected file: %s' % filename)
-
- # And remove the temporary files
- self.RunShellCommand('rm ' + temp_file)
- self.RunShellCommand('rm ' + temp_script)
+ try:
+ # Put the contents in a temporary file
+ self.SetFileContents(temp_file, contents)
+ # Create a script to copy the file contents to its final destination
+ self.SetFileContents(temp_script, 'cat %s > %s' % (temp_file, filename))
+
+ command = 'sh %s' % temp_script
+ command_runner = self._GetProtectedFileCommandRunner()
+ if command_runner:
+ return command_runner(command)
+ else:
+ logging.warning(
+ 'Could not set contents of protected file: %s' % filename)
+ finally:
+ # And remove the temporary files
+ self.RunShellCommand('rm ' + temp_file)
+ self.RunShellCommand('rm ' + temp_script)
def RemovePushedFiles(self):
"""Removes all files pushed with PushIfNeeded() from the device."""
@@ -1891,17 +1899,21 @@ class AndroidCommands(object):
'android',
'pylib',
'efficient_android_directory_copy.sh')
- self._adb.Push(host_script_path, temp_script_file)
- self.EnableAdbRoot
- out = self.RunShellCommand('sh %s %s %s' % (temp_script_file, source, dest),
- timeout_time=120)
- if self._device:
- device_repr = self._device[-4:]
- else:
- device_repr = '????'
- for line in out:
- logging.info('[%s]> %s', device_repr, line)
- self.RunShellCommand('rm %s' % temp_script_file)
+ try:
+ self._adb.Push(host_script_path, temp_script_file)
+ self.EnableAdbRoot
Sami 2014/05/08 15:14:36 This line makes me say hmm...
bulach 2014/05/08 15:25:03 my bad, I didn't spot this.. :( https://coderevie
+ out = self.RunShellCommand('sh %s %s %s' % (temp_script_file,
+ source,
+ dest),
+ timeout_time=120)
+ if self._device:
+ device_repr = self._device[-4:]
+ else:
+ device_repr = '????'
+ for line in out:
+ logging.info('[%s]> %s', device_repr, line)
+ finally:
+ self.RunShellCommand('rm %s' % temp_script_file)
def _GetControlUsbChargingCommand(self):
if self._control_usb_charging_command['cached']:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698