Make it harder to leak temp files on devices
commit9eaaa4a671c891fd6fa20fb7aac7249d28a72eb8
authorcjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Fri, 16 May 2014 03:21:27 +0000 (16 03:21 +0000)
committercjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Fri, 16 May 2014 03:21:27 +0000 (16 03:21 +0000)
tree85d80e5e2e0d0fab1817ad1dbeaecd7d40997a9f
parentadd12abcdc863375db4650019b97d41ef34ad8b0
Make it harder to leak temp files on devices

This extracts the device temp file creation deletion into a context
manager. This context manager will delete the temporary file when
leaving the with: scope.

Also changes logic for finding a temp file from a linear search from 0
to just using a random number (still checking that the file doesn't
exist). Both of these approaches could return the same file in
consecutive calls if the earlier files aren't written to (though it is
nearly impossible with the random number approach instead of essentially
guaranteed).

Removed the temp file name patterns and just added a prefix+suffix
argument to DeviceTempFile (like tempfile.NamedTemporaryFile).

BUG=371054

Review URL: https://codereview.chromium.org/276813002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270917 0039d316-1c4b-4281-b951-d872f2087c98
build/android/pylib/android_commands.py
build/android/pylib/android_commands_unittest.py