From owner-freebsd-current@FreeBSD.ORG Thu Mar 29 00:17:37 2007 Return-Path: X-Original-To: current@FreeBSD.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 640CD16A400 for ; Thu, 29 Mar 2007 00:17:37 +0000 (UTC) (envelope-from nate@root.org) Received: from root.org (root.org [67.118.192.226]) by mx1.freebsd.org (Postfix) with ESMTP id 4CFCF13C43E for ; Thu, 29 Mar 2007 00:17:37 +0000 (UTC) (envelope-from nate@root.org) Received: (qmail 18546 invoked from network); 28 Mar 2007 21:52:31 -0000 Received: from ppp-71-139-28-99.dsl.snfc21.pacbell.net (HELO ?10.0.0.235?) (nate-mail@71.139.28.99) by root.org with ESMTPA; 28 Mar 2007 21:52:31 -0000 Message-ID: <460AE39B.4070706@root.org> Date: Wed, 28 Mar 2007 14:52:27 -0700 From: Nate Lawson User-Agent: Thunderbird 1.5.0.7 (X11/20061027) MIME-Version: 1.0 To: current@FreeBSD.org X-Enigmail-Version: 0.94.1.0 Content-Type: multipart/mixed; boundary="------------070508040504000902030504" Cc: =?ISO-8859-1?Q?Dag-Erling_Sm=F8rgrav?= Subject: libfetch ftp patch for less latency X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Mar 2007 00:17:37 -0000 This is a multi-part message in MIME format. --------------070508040504000902030504 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit To speed up pkg_add and other ftp command channel performance over slow links, change this: >>> PWD <<< 257 "/" >>> CWD pub <<< 250 Directory successfully changed. >>> CWD FreeBSD <<< 250 Directory successfully changed. >>> CWD ports <<< 250 Directory successfully changed. >>> CWD amd64 <<< 250 Directory successfully changed. >>> CWD packages-6-stable <<< 250 Directory successfully changed. >>> CWD Latest <<< 250 Directory successfully changed. >>> MODE S Into this: >>> PWD <<< 257 "/" >>> CWD pub/FreeBSD/ports/amd64/packages-6-stable/Latest <<< 250 Directory successfully changed. All ftp servers I've ever seen support a full path when changing down dirs. This might be a DOS ftp server thing however. In any case, if there is an error to the all-in-one CWD, the code reverts back to legacy behavior of multiple CWDs. -- Nate --------------070508040504000902030504 Content-Type: text/x-patch; name="ftp.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ftp.diff" =================================================================== RCS file: /home/ncvs/src/lib/libfetch/ftp.c,v --- ftp.c 22 Jul 2006 06:01:58 -0000 1.91.2.1 +++ ftp.c 28 Mar 2007 20:42:58 -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,21 @@ return (-1); } } + + /* 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); + + /* 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; --------------070508040504000902030504--