Android: Make sure temporary scripts are deleted from the device
Once we're done using a temporary file, we should delete it. Otherwise the files pile up and the linear search to find an unused one takes longer and longer. This patch also cleans up the previously leaked temporary files from the bots. BUG=371148 R=bulach@chromium.org, jbudorick@chromium.org, yfriedman@chromium.org Review URL: https://codereview.chromium.org/270833004 Patch from Sami Kyostila <skyostil@chromium.org>. git-svn-id: http://src.chromium.org/svn/trunk/src/build@269094 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
4b6823fd7b
Коммит
8ee6b9776f
|
@ -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.
|
||||
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))
|
||||
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:
|
||||
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)
|
||||
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()
|
||||
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']:
|
||||
|
|
Загрузка…
Ссылка в новой задаче