--copy-unsafe-links fix checked in

Dave Dykstra dwd at drdykstra.us
Wed Jan 15 16:29:00 EST 2003

Below is the patch I just checked in to fix --copy-unsafe-links.  As far
as I can tell it has been broken for years, ever since I first put it in.
It bothers me a bit that I can't figure out why I went through the
trouble and mess at the time to introduce a global variable to compare
to wrong information rather than using the parameter already available
in the function, but I've given up trying to figure out why.

In my research into this I also found that 2-1/2 years ago somebody
posted a patch that included a fix for this buried in it, and that I
had promised to integrate his patch but I never did it, I think due to
various other crises that were happening at the time.  I also don't think
I realized that the existing option was broken.  His patch expanded the
--copy-unsafe-links option so that unsafe symlinks on the destination
side are also followed.  I'm sure that could be a useful option, allowing
things like moving some parts of a directory structure on the destination
side to a separate filesystem.  However, it really doesn't have anything
to do with the name "copy-unsafe-links".  I'm thinking that either I
should rename the --copy-unsafe-links option to --follow-unsafe-links
and add this functionality, or add a separate option by that name that
only affects the destination side.  Does anybody have an opinion on those?

- Dave

diff -ur ../rsync.current/flist.c ./flist.c
--- ../rsync.current/flist.c	Sat Jan 11 08:18:02 2003
+++ ./flist.c	Tue Jan 14 16:04:14 2003
@@ -61,8 +61,6 @@
 extern int read_batch;
 extern int write_batch;
-static char topsrcname[MAXPATHLEN];
 static struct exclude_struct **local_exclude_list;
 static struct file_struct null_file;
@@ -221,8 +219,11 @@
 		if (l == -1) 
 			return -1;
 		linkbuf[l] = 0;
-		if (copy_unsafe_links && (topsrcname[0] != '\0') &&
-		    unsafe_symlink(linkbuf, topsrcname)) {
+		if (copy_unsafe_links && unsafe_symlink(linkbuf, path)) {
+			if (verbose > 1) {
+				rprintf(FINFO,"copying unsafe symlink \"%s\" -> \"%s\"\n", 
+					path, linkbuf);
+			}
 			return do_stat(path, buffer);
@@ -895,7 +896,8 @@
 	for (i = 0; i < argc; i++) {
-		char *fname = topsrcname;
+		char fname2[MAXPATHLEN];
+		char *fname = fname2;
 		strlcpy(fname, argv[i], MAXPATHLEN);
@@ -1000,8 +1002,6 @@
-	topsrcname[0] = '\0';
 	if (f != -1) {
 		send_file_entry(NULL, f, 0);
diff -ur ../rsync.current/testsuite/unsafe-byname.test ./testsuite/unsafe-byname.test
--- ../rsync.current/testsuite/unsafe-byname.test	Mon Apr  8 23:49:42 2002
+++ ./testsuite/unsafe-byname.test	Tue Jan 14 16:37:20 2003
@@ -44,12 +44,3 @@
 test_unsafe ../../unsafe/unsafefile    `pwd`/from/safe	safe
 test_unsafe ../files/file1	       `pwd`/from/safe	safe
-# I think these are correct, but I don't really understand the code.
-# Waiting for an answer from dwd
-test_skipped "correct behaviour is unclear"
-# Test suspicious handling of '..' in srcdir
-test_unsafe ../../unsafe/unsafefile    from/safe/../safe	unsafe
-test_unsafe ../files/file1	       from/safe/../safe	safe
diff -ur ../rsync.current/testsuite/unsafe-links.test ./testsuite/unsafe-links.test
--- ../rsync.current/testsuite/unsafe-links.test	Thu Jan  9 10:07:15 2003
+++ ./testsuite/unsafe-links.test	Tue Jan 14 16:45:06 2003
@@ -46,20 +46,13 @@
 test_regular to/links/file2
 test_regular to/links/unsafefile
-#next rsync copy correctly
 echo "rsync with relative path and --copy-unsafe-links";
 $RSYNC -avv --copy-unsafe-links from/safe/ to
 test_symlink to/links/file1
 test_symlink to/links/file2
 test_regular to/links/unsafefile
-# I think these are correct, but I don't really understand the code.
-# Waiting for an answer from dwd
-test_skipped "correct behaviour is unclear"
 rm -rf to
-#next rsync copy incorrectly - links are copied as files not as links
 echo "rsync with relative2 path";
 (cd from; $RSYNC -avv --copy-unsafe-links safe/ ../to)
 test_symlink to/links/file1
@@ -67,7 +60,6 @@
 test_regular to/links/unsafefile
 rm -rf to
-#next rsync copy uncorectly - all links are copied
 echo "rsync with absolute path";
 $RSYNC -avv --copy-unsafe-links `pwd`/from/safe/ to
 test_symlink to/links/file1

More information about the rsync mailing list