mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure _afc_file_read terminates if 0 bytes read.
This commit is contained in:
parent
2792dbc37c
commit
734bccb1b0
@ -902,30 +902,39 @@ class libiMobileDevice():
|
|||||||
'''
|
'''
|
||||||
self._log_location("handle:{0} size:{1:,} mode='{2}'".format(handle.value, size, mode))
|
self._log_location("handle:{0} size:{1:,} mode='{2}'".format(handle.value, size, mode))
|
||||||
|
|
||||||
bytes_read = c_uint(0)
|
|
||||||
|
|
||||||
bytes_remaining = size
|
bytes_remaining = size
|
||||||
if 'b' in mode:
|
if 'b' in mode:
|
||||||
data = bytearray(size)
|
data = bytearray(size)
|
||||||
datatype = c_char * size
|
datatype = c_char * size
|
||||||
while bytes_remaining > 0:
|
while bytes_remaining > 0:
|
||||||
|
bytes_read = c_uint(0)
|
||||||
error = self.lib.afc_file_read(byref(self.afc),
|
error = self.lib.afc_file_read(byref(self.afc),
|
||||||
handle,
|
handle,
|
||||||
byref(datatype.from_buffer(data), size - bytes_remaining),
|
byref(datatype.from_buffer(data), size - bytes_remaining),
|
||||||
bytes_remaining,
|
bytes_remaining,
|
||||||
byref(bytes_read)) & 0xFFFF
|
byref(bytes_read)) & 0xFFFF
|
||||||
if error:
|
if error:
|
||||||
self._log_error(" ERROR: {0} handle:{1}".format(self._afc_error(error), handle))
|
self._log_error(" ERROR: {0} handle:{1}".format(self._afc_error(error), handle.value))
|
||||||
bytes_remaining -= bytes_read.value
|
bytes_remaining = 0
|
||||||
bytes_read = c_uint(0)
|
elif bytes_read.value == 0:
|
||||||
|
self._log_error(" ERROR: reading {0:,} bytes, 0 bytes read, handle:{1}".format(bytes_remaining, handle.value))
|
||||||
|
bytes_remaining = 0
|
||||||
|
else:
|
||||||
|
bytes_remaining -= bytes_read.value
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
data = create_string_buffer(size)
|
data = create_string_buffer(size)
|
||||||
while bytes_remaining > 0:
|
while bytes_remaining > 0:
|
||||||
|
bytes_read = c_uint(0)
|
||||||
error = self.lib.afc_file_read(byref(self.afc), handle, byref(data, size - bytes_remaining), bytes_remaining, byref(bytes_read))
|
error = self.lib.afc_file_read(byref(self.afc), handle, byref(data, size - bytes_remaining), bytes_remaining, byref(bytes_read))
|
||||||
if error:
|
if error:
|
||||||
self._log_error(" ERROR: {0} handle:{1}".format(self._afc_error(error), handle))
|
self._log_error(" ERROR: {0} handle:{1}".format(self._afc_error(error), handle.value))
|
||||||
bytes_remaining -= bytes_read.value
|
bytes_remaining = 0
|
||||||
|
elif bytes_read.value == 0:
|
||||||
|
self._log_error(" ERROR: reading {0:,} bytes, 0 bytes read, handle:{1}".format(bytes_remaining, handle.value))
|
||||||
|
bytes_remaining = 0
|
||||||
|
else:
|
||||||
|
bytes_remaining -= bytes_read.value
|
||||||
return data.value
|
return data.value
|
||||||
|
|
||||||
def _afc_file_write(self, handle, content, mode='w'):
|
def _afc_file_write(self, handle, content, mode='w'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user