]> git.proxmox.com Git - pve-zsync.git/commitdiff
vm_exists: directly check if we look for local guest
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 19 Nov 2018 16:56:33 +0000 (17:56 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 20 Nov 2018 14:46:25 +0000 (15:46 +0100)
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@proxmox.com>
pve-zsync

index 4c00f479a1cf24af02d5abc713e0bb2599e31207..fa7fc37f68b1a6def607e066587c734a1708dd60 100755 (executable)
--- 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"]) };
-
-    return "qemu" if $res;
-
-    eval { $res = run_cmd([@cmd, 'ls',  "$LXC_CONF/$target->{vmid}.conf"]) };
+    my $conf_fn = "$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;
 }