From e844a4a8a8500e6e1cbb53c2a932c2c57bc0ca9f Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sat, 27 Oct 2007 02:19:49 +0000 Subject: [PATCH] When listing a bare module name w/o -r, make sure we list the contents of the module's root directory. --- clientserver.c | 34 ++++++++++++++++++++++++---------- main.c | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/clientserver.c b/clientserver.c index 20a164e6..8cbde16b 100644 --- a/clientserver.c +++ b/clientserver.c @@ -192,21 +192,31 @@ static int exchange_protocols(int f_in, int f_out, char *buf, size_t bufsiz, int int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char *argv[]) { - int i; + int i, modlen; char line[BIGPATHBUFLEN]; char *sargs[MAX_ARGS]; int sargc = 0; - char *p, *path = *argv; + char *p, *modname; - if (argc == 0 && !am_sender) - list_only |= 1; + assert(argc > 0); - if (*path == '/') { + if (**argv == '/') { rprintf(FERROR, "ERROR: The remote path must start with a module name\n"); return -1; } + if (!(p = strchr(*argv, '/'))) + modlen = strlen(*argv); + else + modlen = p - *argv; + + if (!(modname = new_array(char, modlen+1+1))) /* room for '/' & '\0' */ + out_of_memory("start_inband_exchange"); + strlcpy(modname, *argv, modlen + 1); + modname[modlen] = '/'; + modname[modlen+1] = '\0'; + if (!user) user = getenv("USER"); if (!user) @@ -232,7 +242,12 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char rprintf(FERROR, "internal: args[] overflowed in do_cmd()\n"); exit_cleanup(RERR_SYNTAX); } - sargs[sargc++] = *argv++; + if (list_only && strncmp(*argv, modname, modlen) == 0 + && argv[0][modlen] == '\0') + sargs[sargc++] = modname; /* we send "modname/" */ + else + sargs[sargc++] = *argv; + argv++; argc--; } @@ -241,10 +256,7 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char if (verbose > 1) print_child_argv("sending daemon args:", sargs); - p = strchr(path, '/'); - if (p) *p = '\0'; - io_printf(f_out, "%s\n", path); - if (p) *p = '/'; + io_printf(f_out, "%.*s\n", modlen, modname); /* Old servers may just drop the connection here, rather than sending a proper EXIT command. Yuck. */ @@ -303,6 +315,8 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char io_start_multiplex_in(); } + free(modname); + return 0; } diff --git a/main.c b/main.c index 454b7ea6..92b5c44b 100644 --- a/main.c +++ b/main.c @@ -723,7 +723,7 @@ static void do_server_sender(int f_in, int f_out, int argc, char *argv[]) argc--; argv++; - if (argc == 0 && (recurse || list_only)) { + if (argc == 0 && (recurse || xfer_dirs || list_only)) { argc = 1; argv--; argv[0] = "."; -- 2.34.1