Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp Issue PWD commands to the server only when we ac...



details:   https://anonhg.NetBSD.org/src/rev/85f7418a8ab6
branches:  trunk
changeset: 827958:85f7418a8ab6
user:      kre <kre%NetBSD.org@localhost>
date:      Mon Nov 20 21:11:36 2017 +0000

description:
Issue PWD commands to the server only when we actually
need the results, not speculatively, just in case we might.

Allows operation with some broken servers that get confused
by PWD commands in some situations, and saves server round
trips in the (modern) common case of
        ftp ftp://path/name
where we never need to know the results from PWD.

diffstat:

 usr.bin/ftp/cmds.c    |  14 ++++++++------
 usr.bin/ftp/ftp_var.h |   3 ++-
 usr.bin/ftp/util.c    |  10 +++++++---
 3 files changed, 17 insertions(+), 10 deletions(-)

diffs (112 lines):

diff -r 2cf1484473ac -r 85f7418a8ab6 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Mon Nov 20 21:06:54 2017 +0000
+++ b/usr.bin/ftp/cmds.c        Mon Nov 20 21:11:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.137 2016/02/27 16:31:31 christos Exp $      */
+/*     $NetBSD: cmds.c,v 1.138 2017/11/20 21:11:36 kre Exp $   */
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.137 2016/02/27 16:31:31 christos Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.138 2017/11/20 21:11:36 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1158,7 +1158,8 @@
        }
        if (r == COMPLETE) {
                dirchange = 1;
-               updateremotecwd();
+               remotecwd[0] = '\0';
+               remcwdvalid = 0;
        }
 }
 
@@ -1544,9 +1545,9 @@
                UPRINTF("usage: %s\n", argv[0]);
                return;
        }
-       if (! remotecwd[0])
+       if (!remcwdvalid || remotecwd[0] == '\0')
                updateremotecwd();
-       if (! remotecwd[0])
+       if (remotecwd[0] == '\0')
                fprintf(ttyout, "Unable to determine remote directory\n");
        else {
                fprintf(ttyout, "Remote directory: %s\n", remotecwd);
@@ -2359,7 +2360,8 @@
        }
        if (r == COMPLETE) {
                dirchange = 1;
-               updateremotecwd();
+               remotecwd[0] = '\0';
+               remcwdvalid = 0;
        }
 }
 
diff -r 2cf1484473ac -r 85f7418a8ab6 usr.bin/ftp/ftp_var.h
--- a/usr.bin/ftp/ftp_var.h     Mon Nov 20 21:06:54 2017 +0000
+++ b/usr.bin/ftp/ftp_var.h     Mon Nov 20 21:11:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp_var.h,v 1.84 2015/12/16 23:00:39 christos Exp $    */
+/*     $NetBSD: ftp_var.h,v 1.85 2017/11/20 21:11:36 kre Exp $ */
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -269,6 +269,7 @@
 GLOBAL int     unix_proxy;     /* proxy is unix, can use binary for ascii */
 GLOBAL char    localcwd[MAXPATHLEN];   /* local dir */
 GLOBAL char    remotecwd[MAXPATHLEN];  /* remote dir */
+GLOBAL int     remcwdvalid;            /* remotecwd has been updated */
 GLOBAL char   *username;       /* name of user logged in as. (dynamic) */
 
 GLOBAL sa_family_t family;     /* address family to use for connections */
diff -r 2cf1484473ac -r 85f7418a8ab6 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Mon Nov 20 21:06:54 2017 +0000
+++ b/usr.bin/ftp/util.c        Mon Nov 20 21:11:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $   */
+/*     $NetBSD: util.c,v 1.159 2017/11/20 21:11:36 kre Exp $   */
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $");
+__RCSID("$NetBSD: util.c,v 1.159 2017/11/20 21:11:36 kre Exp $");
 #endif /* not lint */
 
 /*
@@ -478,7 +478,8 @@
                }
        }
        updatelocalcwd();
-       updateremotecwd();
+       remotecwd[0] = '\0';
+       remcwdvalid = 0;
 
  cleanup_ftp_login:
        FREEPTR(fuser);
@@ -835,6 +836,7 @@
        size_t   i;
        char    *cp;
 
+       remcwdvalid = 1;        /* whether it works or not, we are done */
        overbose = verbose;
        ocode = code;
        if (ftp_debug == 0)
@@ -1174,6 +1176,8 @@
                case '/':
                case '.':
                case 'c':
+                       if (connected && !remcwdvalid)
+                               updateremotecwd();
                        p2 = connected ? remotecwd : "";
                        updirs = pdirs = 0;
 



Home | Main Index | Thread Index | Old Index