Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Apr 2007 12:37:18 -0700
From:      Nate Lawson <nate@root.org>
To:        =?ISO-8859-1?Q?Dag-Erling_Sm=F8rgrav?= <des@des.no>
Cc:        Yar Tikhiy <yar@comp.chem.msu.su>, freebsd-current@freebsd.org
Subject:   Re: libfetch ftp patch for less latency
Message-ID:  <462BB96E.3050303@root.org>
In-Reply-To: <867is6194t.fsf@dwp.des.no>
References:  <460AE39B.4070706@root.org> <86ps6g5759.fsf@dwp.des.no>	<4617F563.40502@root.org> <200704181648.46348.jhb@freebsd.org>	<20070420074423.GA22594@comp.chem.msu.su> <4628F76F.80608@root.org>	<20070421000649.GD52136@comp.chem.msu.su> <462956BE.3050904@root.org> <867is6194t.fsf@dwp.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------020007010800090305070005
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Dag-Erling Smørgrav wrote:
> Nate Lawson <nate@root.org> writes:
>> Anyone have an issue with me committing the code under an #ifdef, off by
>> default?  I'll make a note in the src about TVFS support as a todo.
> 
> Go ahead.
> 
> DES

Thanks!  Please review the attached patch.

-- 
Nate

--------------020007010800090305070005
Content-Type: text/x-patch;
 name="fetch.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fetch.diff"

Index: src/lib/libfetch/ftp.c
===================================================================
RCS file: /home/ncvs/src/lib/libfetch/ftp.c,v
retrieving revision 1.91.2.1
diff -u -r1.91.2.1 ftp.c
--- src/lib/libfetch/ftp.c	22 Jul 2006 06:01:58 -0000	1.91.2.1
+++ src/lib/libfetch/ftp.c	22 Apr 2007 19:36:16 -0000
@@ -267,6 +267,7 @@
 	char pwd[PATH_MAX];
 	int e, i, len;
 
+	/* If no slashes in name, no need to change dirs. */
 	if ((end = strrchr(file, '/')) == NULL)
 		return (0);
 	if ((e = _ftp_cmd(conn, "PWD")) != FTP_WORKING_DIRECTORY ||
@@ -276,7 +277,8 @@
 	}
 	for (;;) {
 		len = strlen(pwd);
-		/* look for a common prefix */
+
+		/* Look for a common prefix between PWD and dir to fetch. */
 		for (i = 0; i <= len && i <= end - file; ++i)
 			if (pwd[i] != file[i])
 				break;
@@ -284,6 +286,7 @@
 		DEBUG(fprintf(stderr, "have: [%.*s|%s]\n", i, pwd, pwd + i));
 		DEBUG(fprintf(stderr, "want: [%.*s|%s]\n", i, file, file + i));
 #endif
+		/* Keep going up a dir until we have a matching prefix. */
 		if (pwd[i] == '\0' && (file[i - 1] == '/' || file[i] == '/'))
 			break;
 		if ((e = _ftp_cmd(conn, "CDUP")) != FTP_FILE_ACTION_OK ||
@@ -293,6 +296,23 @@
 			return (-1);
 		}
 	}
+
+#ifdef FTP_COMBINE_CWDS
+	/* Skip leading slashes, even "////". */
+	for (beg = file + i; beg < end && *beg == '/'; ++beg, ++i)
+		/* nothing */ ;
+
+	/* If there is no trailing dir, we're already there. */
+	if (beg >= end)
+		return (0);
+
+	/* Change to the directory all in one chunk (e.g., foo/bar/baz). */
+	e = _ftp_cmd(conn, "CWD %.*s", (int)(end - beg), beg);
+	if (e == FTP_FILE_ACTION_OK)
+		return (0);
+#endif /* FTP_COMBINE_CWDS */
+
+	/* That didn't work so go back to legacy behavior (multiple CWDs). */
 	for (beg = file + i; beg < end; beg = file + i + 1) {
 		while (*beg == '/')
 			++beg, ++i;
@@ -966,6 +986,8 @@
 	if ((e = _ftp_authenticate(conn, url, purl)) != FTP_LOGGED_IN)
 		goto fouch;
 
+	/* TODO: Request extended features supported, if any (RFC 3659). */
+
 	/* done */
 	return (conn);
 

--------------020007010800090305070005--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?462BB96E.3050303>