mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fixed libimobiledevice _afc_file_write wrapper to loop until all bytes are written.
_afc_file_write is used by the idevice interface to copy files to the idevice. This fix has been successfully tested by round tripping a 500 MB file from the PC to the device and back again, and checking that the before and after files are identical.
This commit is contained in:
parent
99cb07ea09
commit
f5bff92ac4
@ -958,24 +958,31 @@ class libiMobileDevice():
|
|||||||
'''
|
'''
|
||||||
self._log_location("handle:{0} mode='{1}'".format(handle.value, mode))
|
self._log_location("handle:{0} mode='{1}'".format(handle.value, mode))
|
||||||
|
|
||||||
bytes_written = c_uint(0)
|
size = len(content)
|
||||||
|
|
||||||
if 'b' in mode:
|
if 'b' in mode:
|
||||||
# Content already contained in a bytearray()
|
# Content already contained in a bytearray()
|
||||||
data = content
|
data = content
|
||||||
datatype = c_char * len(content)
|
datatype = c_char * size
|
||||||
else:
|
else:
|
||||||
data = bytearray(content, 'utf-8')
|
data = bytearray(content, 'utf-8')
|
||||||
datatype = c_char * len(content)
|
datatype = c_char * size
|
||||||
|
|
||||||
error = self.lib.afc_file_write(byref(self.afc),
|
bytes_remaining = size
|
||||||
|
while bytes_remaining > 0:
|
||||||
|
bytes_written = c_uint(0)
|
||||||
|
error = self.lib.afc_file_write(byref(self.afc),
|
||||||
handle,
|
handle,
|
||||||
byref(datatype.from_buffer(data)),
|
byref(datatype.from_buffer(data), size - bytes_remaining),
|
||||||
len(content),
|
bytes_remaining,
|
||||||
byref(bytes_written)) & 0xFFFF
|
byref(bytes_written)) & 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))
|
||||||
return False
|
return False
|
||||||
|
elif bytes_written.value == 0:
|
||||||
|
self._log_error(" ERROR: writing {0:,} bytes, 0 bytes written, handle:{1}".format(bytes_remaining, handle.value))
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
bytes_remaining -= bytes_written.value
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _afc_get_device_info(self):
|
def _afc_get_device_info(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user