mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
virsh: Remove unnecessary else branches
In a few cases we call a public API, wrapped in an if() statement with both branches written out explicitly. The error branch jumps onto cleanup label, while the successful prints out a message. Right after these ifs there's 'ret = true;' and the cleanup label. The code is a bit more readable if only the error branch is kept and printing happens at the same level as setting the ret variable. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
This commit is contained in:
parent
a4056d52eb
commit
842cfc9d41
@ -1024,13 +1024,12 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
||||
if (!dev)
|
||||
goto cleanup;
|
||||
|
||||
if (virNodeDeviceUndefine(dev, 0) == 0) {
|
||||
vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
|
||||
} else {
|
||||
if (virNodeDeviceUndefine(dev, 0) < 0) {
|
||||
vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
|
||||
ret = true;
|
||||
cleanup:
|
||||
return ret;
|
||||
|
@ -411,14 +411,14 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((vol = virStorageVolCreateXML(pool, buffer, flags))) {
|
||||
vshPrintExtra(ctl, _("Vol %s created from %s\n"),
|
||||
virStorageVolGetName(vol), from);
|
||||
ret = true;
|
||||
} else {
|
||||
if (!(vol = virStorageVolCreateXML(pool, buffer, flags))) {
|
||||
vshError(ctl, _("Failed to create vol from %s"), from);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vshPrintExtra(ctl, _("Vol %s created from %s\n"),
|
||||
virStorageVolGetName(vol), from);
|
||||
ret = true;
|
||||
cleanup:
|
||||
return ret;
|
||||
}
|
||||
@ -489,14 +489,13 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags);
|
||||
|
||||
if (newvol != NULL) {
|
||||
vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
|
||||
virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
|
||||
} else {
|
||||
if (!newvol) {
|
||||
vshError(ctl, _("Failed to create vol from %s"), from);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
|
||||
virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
|
||||
ret = true;
|
||||
cleanup:
|
||||
return ret;
|
||||
@ -1147,20 +1146,19 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virStorageVolResize(vol, capacity, flags) == 0) {
|
||||
vshPrintExtra(ctl,
|
||||
delta ? _("Size of volume '%s' successfully changed by %s\n")
|
||||
: _("Size of volume '%s' successfully changed to %s\n"),
|
||||
virStorageVolGetName(vol), capacityStr);
|
||||
ret = true;
|
||||
} else {
|
||||
if (virStorageVolResize(vol, capacity, flags) < 0) {
|
||||
vshError(ctl,
|
||||
delta ? _("Failed to change size of volume '%s' by %s")
|
||||
: _("Failed to change size of volume '%s' to %s"),
|
||||
virStorageVolGetName(vol), capacityStr);
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vshPrintExtra(ctl,
|
||||
delta ? _("Size of volume '%s' successfully changed by %s\n")
|
||||
: _("Size of volume '%s' successfully changed to %s\n"),
|
||||
virStorageVolGetName(vol), capacityStr);
|
||||
ret = true;
|
||||
cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user