[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#308290: libgphoto2-2: fails to import avis from Canon IXUS IIs



This has been fixed in libgphoto2-2 2.1.5-6 (as well as a duplicate
filed as 301945 against gphoto2).  It has been built on every arch.

Release team, this allows libgphoto2 to work correctly with sarge
libusb version (in order to download big files, mostly movies now but
with resolutions increasing, it will affect more and more single
pictures).

Patch is attached and has also been applied upstream (upstream bug
report and patch is available[1]).


Regards,

        Frederic

[1] http://sourceforge.net/tracker/index.php?func=detail&aid=1162373&group_id=8874&atid=108874
--- libgphoto2-2.1.5.orig/camlibs/ptp2/library.c
+++ libgphoto2-2.1.5/camlibs/ptp2/library.c
@@ -497,19 +497,32 @@
 ptp_read_func (unsigned char *bytes, unsigned int size, void *data, unsigned int *readbytes)
 {
 	Camera *camera = ((PTPData *)data)->camera;
-	int result;
+	int toread, result = GP_ERROR, curread = 0;
 
-	/*
-	 * gp_port_read returns (in case of success) the number of bytes read.
+	/* Split into small blocks. Too large blocks (>1x MB) would
+	 * timeout.
 	 */
-	result = gp_port_read (camera->port, bytes, size);
-	if (result==0) result = gp_port_read (camera->port, bytes, size);
-	if (result >= 0) {
-		*readbytes = result;
+	while (curread < size) {
+		toread =size - curread;
+		if (toread > 4096)
+			toread = 4096;
+		result = gp_port_read (camera->port, bytes + curread, toread);
+		if (result == 0) {
+			result = gp_port_read (camera->port, bytes + curread, toread);
+			if (result < 0) {
+				break;
+			}
+		}
+		if (result < 0)
+			break;
+		curread += result;
+		if (result < toread) /* short reads are common */
+			break;
+	}
+	if (result > 0) {
+		*readbytes = curread;
 		return (PTP_RC_OK);
-	} else
-	{
-		perror("gp_port_read");
+	} else {
 		return (translate_gp_result (result));
 	}
 }

Reply to: