[pve-devel] [PATCH zsync 2/2] vm_exists: directly check if we look for local guest

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Nov 19 17:56:33 CET 2018


no need to make a call to ls if we just can check directly..

also remove a (possible problematic)
> my $foo = 'bar' if $boolean;
construct

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 pve-zsync | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/pve-zsync b/pve-zsync
index 4c00f47..fa7fc37 100755
--- a/pve-zsync
+++ b/pve-zsync
@@ -468,19 +468,18 @@ sub list {
 sub vm_exists {
     my ($target, $user) = @_;
 
-    my @cmd = ('ssh', "$user\@$target->{ip}", '--') if $target->{ip};
-
-    my $res = undef;
-
     return undef if !defined($target->{vmid});
 
-    eval { $res = run_cmd([@cmd, 'ls',  "$QEMU_CONF/$target->{vmid}.conf"]) };
+    my $conf_fn = "$target->{vmid}.conf";
 
-    return "qemu" if $res;
-
-    eval { $res = run_cmd([@cmd, 'ls',  "$LXC_CONF/$target->{vmid}.conf"]) };
-
-    return "lxc" if $res;
+    if ($target->{ip}) {
+	my @cmd = ('ssh', "$user\@$target->{ip}", '--', '/bin/ls');
+	return "qemu" if eval { run_cmd([@cmd, "$QEMU_CONF/$conf_fn"]) };
+	return "lxc" if  eval { run_cmd([@cmd, "$LXC_CONF/$conf_fn"]) };
+    } else {
+	return "qemu" if -f "$QEMU_CONF/$conf_fn";
+	return "lxc" if -f "$LXC_CONF/$conf_fn";
+    }
 
     return undef;
 }
-- 
2.19.1





More information about the pve-devel mailing list