[libvirt PATCH] virsh: Make code flow in cmdManagedSaveRemove more straightforward

Jiri Denemark posted 1 patch 2 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/7c0012dee7fa6ff69bfdb5711a3ad8e16e18f12e.1631718897.git.jdenemar@redhat.com
tools/virsh-domain.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
[libvirt PATCH] virsh: Make code flow in cmdManagedSaveRemove more straightforward
Posted by Jiri Denemark 2 years, 7 months ago
By doing so we can get rid of the code which violates our coding style
guidelines.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tools/virsh-domain.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index e5bd1fdd75..ca56c3b33d 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4788,18 +4788,19 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    if (hassave) {
-        if (virDomainManagedSaveRemove(dom, 0) < 0) {
-            vshError(ctl, _("Failed to remove managed save image for domain '%s'"),
-                     name);
-            return false;
-        }
-        else
-            vshPrintExtra(ctl, _("Removed managedsave image for domain '%s'"), name);
-    }
-    else
+    if (hassave == 0) {
         vshPrintExtra(ctl, _("Domain '%s' has no manage save image; removal skipped"),
                       name);
+        return true;
+    }
+
+    if (virDomainManagedSaveRemove(dom, 0) < 0) {
+        vshError(ctl, _("Failed to remove managed save image for domain '%s'"),
+                 name);
+        return false;
+    }
+
+    vshPrintExtra(ctl, _("Removed managedsave image for domain '%s'"), name);
 
     return true;
 }
-- 
2.33.0

Re: [libvirt PATCH] virsh: Make code flow in cmdManagedSaveRemove more straightforward
Posted by Jonathon Jongsma 2 years, 7 months ago
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>

On Wed, Sep 15, 2021 at 10:16 AM Jiri Denemark <jdenemar@redhat.com> wrote:
>
> By doing so we can get rid of the code which violates our coding style
> guidelines.
>
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  tools/virsh-domain.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index e5bd1fdd75..ca56c3b33d 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -4788,18 +4788,19 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
>          return false;
>      }
>
> -    if (hassave) {
> -        if (virDomainManagedSaveRemove(dom, 0) < 0) {
> -            vshError(ctl, _("Failed to remove managed save image for domain '%s'"),
> -                     name);
> -            return false;
> -        }
> -        else
> -            vshPrintExtra(ctl, _("Removed managedsave image for domain '%s'"), name);
> -    }
> -    else
> +    if (hassave == 0) {
>          vshPrintExtra(ctl, _("Domain '%s' has no manage save image; removal skipped"),
>                        name);
> +        return true;
> +    }
> +
> +    if (virDomainManagedSaveRemove(dom, 0) < 0) {
> +        vshError(ctl, _("Failed to remove managed save image for domain '%s'"),
> +                 name);
> +        return false;
> +    }
> +
> +    vshPrintExtra(ctl, _("Removed managedsave image for domain '%s'"), name);
>
>      return true;
>  }
> --
> 2.33.0
>