From 8bd3742ddc872e8a5414c5ee74a8ba4aec6dca95 Mon Sep 17 00:00:00 2001
From: Shaoqi Bai <sbai@pivotal.io>
Date: Thu, 21 Mar 2019 23:20:12 +0800
Subject: [PATCH 1/2] Refactors the code for the new option in PostgresNode.pm

---
 src/test/perl/PostgresNode.pm  | 14 +++++++++++---
 src/test/perl/RecursiveCopy.pm | 20 ++++++++++++++++----
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm
index 0634aefd20..b339a7f4f0 100644
--- a/src/test/perl/PostgresNode.pm
+++ b/src/test/perl/PostgresNode.pm
@@ -534,14 +534,22 @@ target server since it isn't done by default.
 
 sub backup
 {
-	my ($self, $backup_name) = @_;
+	my ($self, $backup_name, %params) = @_;
 	my $backup_path = $self->backup_dir . '/' . $backup_name;
 	my $port        = $self->port;
 	my $name        = $self->name;
 
 	print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
-	TestLib::system_or_bail('pg_basebackup', '-D', $backup_path, '-p', $port,
-		'--no-sync');
+
+	if (defined $params{has_tablespace_mapping}) {
+		TestLib::system_or_bail('pg_basebackup', '-D', $backup_path, '-p', $port,
+			"--tablespace-mapping=" . $params{has_tablespace_mapping},
+			'--no-sync');
+	} else {
+		TestLib::system_or_bail('pg_basebackup', '-D', $backup_path, '-p', $port,
+			'--no-sync');
+	}
+
 	print "# Backup finished\n";
 	return;
 }
diff --git a/src/test/perl/RecursiveCopy.pm b/src/test/perl/RecursiveCopy.pm
index baf5d0ac63..d684463884 100644
--- a/src/test/perl/RecursiveCopy.pm
+++ b/src/test/perl/RecursiveCopy.pm
@@ -97,14 +97,26 @@ sub _copypath_recurse
 	# invoke the filter and skip all further operation if it returns false
 	return 1 unless &$filterfn($curr_path);
 
-	# Check for symlink -- needed only on source dir
-	# (note: this will fall through quietly if file is already gone)
-	croak "Cannot operate on symlink \"$srcpath\"" if -l $srcpath;
-
 	# Abort if destination path already exists.  Should we allow directories
 	# to exist already?
 	croak "Destination path \"$destpath\" already exists" if -e $destpath;
 
+	# Check for symlink -- needed only on source dir, only allow symlink
+	# when under pg_tblspc
+	# (note: this will fall through quietly if file is already gone)
+	if (-l $srcpath)
+	{
+		if (dirname($srcpath) =~ /pg_tblspc$/)
+		{
+			my $dst = readlink($srcpath);
+			symlink($dst, $destpath);
+			return 1;
+		}
+		else
+		{
+			croak "Cannot operate on symlink \"$srcpath\"";
+		}
+	}
 	# If this source path is a file, simply copy it to destination with the
 	# same name and we're done.
 	if (-f $srcpath)
-- 
2.19.1

