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

Side by Side Diff: build/android/pylib/utils/device_temp_file.py

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """A temp file that automatically gets pushed and deleted from a device.""" 5 """A temp file that automatically gets pushed and deleted from a device."""
6 6
7 # pylint: disable=W0622 7 # pylint: disable=W0622
8 8
9 import random 9 import random
10 import time 10 import time
(...skipping 25 matching lines...) Expand all
36 try: 36 try:
37 self._adb.Shell('test -e %s' % self.name_quoted) 37 self._adb.Shell('test -e %s' % self.name_quoted)
38 except device_errors.AdbCommandFailedError: 38 except device_errors.AdbCommandFailedError:
39 break # file does not exist 39 break # file does not exist
40 40
41 # Immediately touch the file, so other temp files can't get the same name. 41 # Immediately touch the file, so other temp files can't get the same name.
42 self._adb.Shell('touch %s' % self.name_quoted) 42 self._adb.Shell('touch %s' % self.name_quoted)
43 43
44 def close(self): 44 def close(self):
45 """Deletes the temporary file from the device.""" 45 """Deletes the temporary file from the device."""
46 # we use -f to ignore errors if the file is already gone 46 # ignore exception if the file is already gone.
47 self._adb.Shell('rm -f %s' % self.name_quoted) 47 try:
48 self._adb.Shell('rm -f %s' % self.name_quoted)
49 except device_errors.AdbCommandFailedError:
50 # file does not exist on Android version without 'rm -f' support (ICS)
51 pass
48 52
49 def __enter__(self): 53 def __enter__(self):
50 return self 54 return self
51 55
52 def __exit__(self, type, value, traceback): 56 def __exit__(self, type, value, traceback):
53 self.close() 57 self.close()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698