From: Marcus M. <ma...@je...> - 2018-03-12 20:36:08
|
Hi, I have applied this patch (restored the associatioon check using mtpfile->filetype) Ciao, Marcus On Sat, Mar 10, 2018 at 08:34:49AM -0800, Philip Langdale wrote: > Due to limitations in the MTP spec, retrieving the file size for > > 4GB files is a multi-step process, currently encapsulated by > LIBMTP_Get_File_Metadata(). > > However, the Get_File methods currently use ptp_object_want directly, > which means that they don't have access to the file size and end up > passing inaccurate information to the progress callback. > > So, let's call LIBMTP_Get_File_Metadata() instead. > > Signed-off-by: Philip Langdale <ph...@ov...> > --- > src/libmtp.c | 28 ++++++++++++---------------- > 1 file changed, 12 insertions(+), 16 deletions(-) > > diff --git a/src/libmtp.c b/src/libmtp.c > index 95d2b77..5577588 100644 > --- a/src/libmtp.c > +++ b/src/libmtp.c > @@ -5287,26 +5287,24 @@ int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t *device, > uint16_t ret; > PTPParams *params = (PTPParams *) device->params; > PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; > - PTPObject *ob; > > - ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob); > - if (ret != PTP_RC_OK) { > + LIBMTP_file_t *mtpfile = LIBMTP_Get_Filemetadata(device, id); > + if (mtpfile == NULL) { > add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Could not get object info."); > return -1; > } > - if (ob->oi.ObjectFormat == PTP_OFC_Association) { > - add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Bad object format."); > - return -1; > - } > > // Callbacks > ptp_usb->callback_active = 1; > - ptp_usb->current_transfer_total = ob->oi.ObjectCompressedSize+ > + ptp_usb->current_transfer_total = mtpfile->filesize + > PTP_USB_BULK_HDR_LEN+sizeof(uint32_t); // Request length, one parameter > ptp_usb->current_transfer_complete = 0; > ptp_usb->current_transfer_callback = callback; > ptp_usb->current_transfer_callback_data = data; > > + // Don't need mtpfile anymore > + LIBMTP_destroy_file_t(mtpfile); > + > ret = ptp_getobject_tofd(params, id, fd); > > ptp_usb->callback_active = 0; > @@ -5349,29 +5347,27 @@ int LIBMTP_Get_File_To_Handler(LIBMTP_mtpdevice_t *device, > LIBMTP_progressfunc_t const callback, > void const * const data) > { > - PTPObject *ob; > uint16_t ret; > PTPParams *params = (PTPParams *) device->params; > PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; > > - ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob); > - if (ret != PTP_RC_OK) { > + LIBMTP_file_t *mtpfile = LIBMTP_Get_Filemetadata(device, id); > + if (mtpfile == NULL) { > add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Could not get object info."); > return -1; > } > - if (ob->oi.ObjectFormat == PTP_OFC_Association) { > - add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Bad object format."); > - return -1; > - } > > // Callbacks > ptp_usb->callback_active = 1; > - ptp_usb->current_transfer_total = ob->oi.ObjectCompressedSize+ > + ptp_usb->current_transfer_total = mtpfile->filesize + > PTP_USB_BULK_HDR_LEN+sizeof(uint32_t); // Request length, one parameter > ptp_usb->current_transfer_complete = 0; > ptp_usb->current_transfer_callback = callback; > ptp_usb->current_transfer_callback_data = data; > > + // Don't need mtpfile anymore > + LIBMTP_destroy_file_t(mtpfile); > + > MTPDataHandler mtp_handler; > mtp_handler.getfunc = NULL; > mtp_handler.putfunc = put_func; > -- > 2.14.1 > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Libmtp-discuss mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libmtp-discuss |