From 2154309a544dd5af50623e07e9b2f766ef93a159 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Fri, 21 Mar 2003 22:10:44 +0000 Subject: [PATCH] Optimized the implied-directory code to avoid putting so many duplicate dirs into the file list. --- flist.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/flist.c b/flist.c index b37a1924..a6f38f9a 100644 --- a/flist.c +++ b/flist.c @@ -942,31 +942,37 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) dir = fname; fname = p + 1; } - } else if (f != -1 && (p = strrchr(fname, '/'))) { + } else if (f != -1 && (p=strrchr(fname,'/')) && p != fname) { /* this ensures we send the intermediate directories, thus getting their permissions right */ + char *lp = lastpath, *fn = fname, *slash = fname; *p = 0; - if (strcmp(lastpath, fname)) { - strlcpy(lastpath, fname, sizeof(lastpath)); - *p = '/'; - for (p = fname + 1; (p = strchr(p, '/')); - p++) { - int copy_links_saved = copy_links; - int recurse_saved = recurse; - *p = 0; - copy_links = copy_unsafe_links; - /* set recurse to 1 to prevent make_file - from ignoring directory, but still - turn off the recursive parameter to - send_file_name */ - recurse = 1; - send_file_name(f, flist, fname, 0, - 0); - copy_links = copy_links_saved; - recurse = recurse_saved; - *p = '/'; + /* Skip any initial directories in our path that we + * have in common with lastpath. */ + while (*fn && *lp == *fn) { + if (*fn == '/') + slash = fn; + lp++, fn++; + } + *p = '/'; + if (fn != p || (*lp && *lp != '/')) { + int copy_links_saved = copy_links; + int recurse_saved = recurse; + copy_links = copy_unsafe_links; + /* set recurse to 1 to prevent make_file + * from ignoring directory, but still + * turn off the recursive parameter to + * send_file_name */ + recurse = 1; + while ((slash = strchr(slash+1, '/')) != 0) { + *slash = 0; + send_file_name(f, flist, fname, 0, 0); + *slash = '/'; } - } else { + copy_links = copy_links_saved; + recurse = recurse_saved; + *p = 0; + strlcpy(lastpath, fname, sizeof lastpath); *p = '/'; } } -- 2.34.1