Bug 1135255 - Fix mozdevice tempfile handling on Windows. r=gbrown

This commit is contained in:
William Lachance 2015-02-23 10:56:50 -05:00
parent bc602afd40
commit 88833b6c0c

View File

@ -408,25 +408,20 @@ class DeviceManagerADB(DeviceManager):
def pullFile(self, remoteFile, offset=None, length=None):
# TODO: add debug flags and allow for printing stdout
localFile = tempfile.mkstemp()[1]
self._runPull(remoteFile, localFile)
f = open(localFile, 'r')
# ADB pull does not support offset and length, but we can instead
# read only the requested portion of the local file
if offset is not None and length is not None:
f.seek(offset)
ret = f.read(length)
elif offset is not None:
f.seek(offset)
ret = f.read()
else:
ret = f.read()
f.close()
mozfile.remove(localFile)
return ret
with mozfile.NamedTemporaryFile() as tf:
self._runPull(remoteFile, tf.name)
# we need to reopen the file to get the written contents
with open(tf.name) as tf2:
# ADB pull does not support offset and length, but we can
# instead read only the requested portion of the local file
if offset is not None and length is not None:
tf2.seek(offset)
return tf2.read(length)
elif offset is not None:
tf2.seek(offset)
return tf2.read()
else:
return tf2.read()
def getFile(self, remoteFile, localFile):
self._runPull(remoteFile, localFile)
@ -445,16 +440,10 @@ class DeviceManagerADB(DeviceManager):
"""
Return the md5 sum of a file on the device
"""
localFile = tempfile.mkstemp()[1]
localFile = self._runPull(remoteFile, localFile)
with tempfile.NamedTemporaryFile() as f:
self._runPull(remoteFile, f.name)
if localFile is None:
return None
md5 = self._getLocalHash(localFile)
mozfile.remove(localFile)
return md5
return self._getLocalHash(f.name)
def _setupDeviceRoot(self, deviceRoot):
# user-specified device root, create it and return it