Discussion:
[pve-devel] [PATCH zsync 1/2] fix #1587: sync: check if job state is defined
Thomas Lamprecht
2018-11-19 16:56:32 UTC
Permalink
just because the $job hash is populated it's state key doesn't needs
to be..

Signed-off-by: Thomas Lamprecht <***@proxmox.com>
---
pve-zsync | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pve-zsync b/pve-zsync
index b9a6995..4c00f47 100755
--- a/pve-zsync
+++ b/pve-zsync
@@ -574,7 +574,7 @@ sub sync {
$job = get_job($param);
};

- if ($job && $job->{state} eq "syncing") {
+ if ($job && defined($job->{state}) && $job->{state} eq "syncing") {
die "Job --source $param->{source} --name $param->{name} is syncing at the moment";
}
--
2.19.1
Thomas Lamprecht
2018-11-19 16:56:33 UTC
Permalink
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 <***@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
Wolfgang Bumiller
2018-11-20 15:09:43 UTC
Permalink
applied both patches

Loading...