[pve-devel] [PATCH zsync 06/10] add check_dataset_exists function

Fabian Ebner f.ebner at proxmox.com
Tue May 4 10:10:00 CEST 2021


as a generalization and replacement of check_pool_exists.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 pve-zsync | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/pve-zsync b/pve-zsync
index 93b0d0d..a327d42 100755
--- a/pve-zsync
+++ b/pve-zsync
@@ -152,15 +152,15 @@ sub get_status {
     return undef;
 }
 
-sub check_pool_exists {
-    my ($target, $user) = @_;
+sub check_dataset_exists {
+    my ($dataset, $ip, $user) = @_;
 
     my $cmd = [];
 
-    if ($target->{ip}) {
-	push @$cmd, 'ssh', "$user\@$target->{ip}", '--';
+    if ($ip) {
+	push @$cmd, 'ssh', "$user\@$ip", '--';
     }
-    push @$cmd, 'zfs', 'list', '-H', '--', $target->{all};
+    push @$cmd, 'zfs', 'list', '-H', '--', $dataset;
     eval {
 	run_cmd($cmd);
     };
@@ -517,10 +517,12 @@ sub init {
 	    run_cmd(['ssh-copy-id', '-i', '/root/.ssh/id_rsa.pub', "$param->{source_user}\@$ip"]);
 	}
 
-	die "Pool $dest->{all} does not exists\n" if !check_pool_exists($dest, $param->{dest_user});
+	die "Pool $dest->{all} does not exist\n"
+	    if !check_dataset_exists($dest->{all}, $dest->{ip}, $param->{dest_user});
 
 	if (!defined($source->{vmid})) {
-	    die "Pool $source->{all} does not exists\n" if !check_pool_exists($source, $param->{source_user});
+	    die "Pool $source->{all} does not exist\n"
+		if !check_dataset_exists($source->{all}, $source->{ip}, $param->{source_user});
 	}
 
 	my $vm_type = vm_exists($source, $param->{source_user});
-- 
2.20.1





More information about the pve-devel mailing list