From 0b70bfc0d86add94bad09cd7f5ef78e3fed92daf Mon Sep 17 00:00:00 2001
From: "Alan J. Pippin" <alan@pippins.net>
Date: Wed, 22 Sep 2021 17:31:24 -0600
Subject: [PATCH] Use expect_empty_remote_list flag when checking if remote
 list should be empty or not

Change-Id: I3d7820c19f4549163d946668f2c3c99a3d5f79fe
---
 zfs-replicate | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/zfs-replicate b/zfs-replicate
index e6e6dd5..60a2345 100755
--- a/zfs-replicate
+++ b/zfs-replicate
@@ -158,8 +158,10 @@ $ssh $remote \
     $zfs list -H -t snapshot |
     grep ^${remote_fs}@ |
     awk '{print$1}' > $remote_list
-if [ $? != 0 ]; then
-  fatal_and_exit "-E- remote $zfs list on $hostname command failed" $mailto
+if [[ $? != 0 ]] && [[ $expect_empty_remote_list == 0 ]]; then
+  echo "-W- Unable to find $remote_fs on the remote host $hostname. Unable to proceed since the"
+  echo "    expect_empty_remote_list option has not been set to allow this, skipping replicate operation."
+  fatal_and_exit "-E- remote $zfs list on $hostname for $remote_fs command failed" $mailto
 fi
 
 # List the snapshots on the local machine.
-- 
2.34.1