Since there is a check on buf through virBufferError(), it is not necessary to check desc again. --- tools/virsh-domain.c | 62 +++++++++++++++++++++---------------------------- 1 files changed, 27 insertions(+), 35 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e47877b..a8a0105 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6724,45 +6724,37 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } desc = virBufferContentAndReset(&buf); - if (edit || desc) { - if (!desc) { - desc = vshGetDomainDescription(ctl, dom, title, - config?VIR_DOMAIN_XML_INACTIVE:0); - if (!desc) - goto cleanup; - } - - if (edit) { - /* Create and open the temporary file. */ - if (!(tmp = vshEditWriteToTempFile(ctl, desc))) - goto cleanup; + if (edit) { + /* Create and open the temporary file. */ + if (!(tmp = vshEditWriteToTempFile(ctl, desc))) + goto cleanup; - /* Start the editor. */ - if (vshEditFile(ctl, tmp) == -1) - goto cleanup; + /* Start the editor. */ + if (vshEditFile(ctl, tmp) == -1) + goto cleanup; - /* Read back the edited file. */ - if (!(desc_edited = vshEditReadBackFile(ctl, tmp))) - goto cleanup; + /* Read back the edited file. */ + if (!(desc_edited = vshEditReadBackFile(ctl, tmp))) + goto cleanup; - /* strip a possible newline at the end of file; some - * editors enforce a newline, this makes editing the title - * more convenient */ - if (title && - (tmpstr = strrchr(desc_edited, '\n')) && - *(tmpstr+1) == '\0') - *tmpstr = '\0'; - - /* Compare original XML with edited. Has it changed at all? */ - if (STREQ(desc, desc_edited)) { - vshPrint(ctl, _("Domain description not changed.\n")); - ret = true; - goto cleanup; - } + /* strip a possible newline at the end of file; some + * editors enforce a newline, this makes editing the title + * more convenient */ + if (title && + (tmpstr = strrchr(desc_edited, '\n')) && + *(tmpstr+1) == '\0') + *tmpstr = '\0'; + + /* Compare original XML with edited. Has it changed at all? */ + if (STREQ(desc, desc_edited)) { + vshPrint(ctl, _("Domain description not changed.\n")); + ret = true; + goto cleanup; + } - VIR_FREE(desc); - desc = desc_edited; - desc_edited = NULL; + VIR_FREE(desc); + desc = desc_edited; + desc_edited = NULL; } if (virDomainSetMetadata(dom, type, desc, NULL, NULL, flags) < 0) { -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list