From 16802529fe0441d1c6349314f976952388177612 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 20 Jan 2018 22:51:38 -0800 Subject: [PATCH] cpdup - Additional fixes for -X absolute_path * When an absolute path is specified the file is connsidered to be local to the machine and is not opened on a remote source. --- bin/cpdup/cpdup.1 | 8 +++++--- bin/cpdup/cpdup.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/cpdup/cpdup.1 b/bin/cpdup/cpdup.1 index d19205ac35..f0071d7905 100644 --- a/bin/cpdup/cpdup.1 +++ b/bin/cpdup/cpdup.1 @@ -243,7 +243,7 @@ not used then the filename is not considered special and will be copied along with everything else. .It Fl X Ar file -Works the same as +Works similarly to .Fl x but allows you to specify the name of the exclusion file. This file is automatically excluded from the copy. Only one exclusion file may be @@ -252,12 +252,14 @@ specified. When an absolute path is used, the same exclusive file is read for every directory and may contain full paths or wildcarded paths based on the full source path as specified on the cpdup command line. +In this situation, the exclusive file is read from the host running +the command, NOT from the source host (if remote). .Pp When a relative path is used (or .Fl x is specified), the exclusion file is only applicable to the directory -it resides in and only path elements (the directory elements) are matched -against it. +it resides in on the source host and only path elements (the directory +elements) are matched against it. .El .Sh REMOTE COPYING .Nm diff --git a/bin/cpdup/cpdup.c b/bin/cpdup/cpdup.c index 4137681e5a..868bd392fa 100644 --- a/bin/cpdup/cpdup.c +++ b/bin/cpdup/cpdup.c @@ -1373,6 +1373,7 @@ ScanDir(List *list, struct HostConf *host, const char *path, int64_t *CountReadBytes, int n) { DIR *dir; + struct HostConf *cphost; struct HCDirEntry *den; struct stat *statptr; @@ -1391,13 +1392,16 @@ ScanDir(List *list, struct HostConf *host, const char *path, if (UseCpFile[0] == '/') { fpath = mprintf("%s", UseCpFile); + cphost = NULL; } else { fpath = mprintf("%s/%s", path, UseCpFile); + AddList(list, strrchr(fpath, '/') + 1, 1, NULL); + cphost = host; } - AddList(list, strrchr(fpath, '/') + 1, 1, NULL); - if ((fd = hc_open(host, fpath, O_RDONLY, 0)) >= 0) { + fd = hc_open(cphost, fpath, O_RDONLY, 0); + if (fd >= 0) { bufused = 0; - while ((nread = hc_read(host, fd, buf + bufused, + while ((nread = hc_read(cphost, fd, buf + bufused, GETBUFSIZE - bufused - 1)) > 0) { *CountReadBytes += nread; bufused += nread; @@ -1415,7 +1419,7 @@ ScanDir(List *list, struct HostConf *host, const char *path, buf[bufused] = 0; AddList(list, buf, 1, NULL); } - hc_close(host, fd); + hc_close(cphost, fd); } free(fpath); free(buf); -- 2.41.0