virStreamPtr st = NULL;
const char *name = NULL;
unsigned long long offset = 0, length = 0;
- bool created = true;
+ bool created = false;
if (!vshConnectionUsability(ctl, ctl->conn))
- goto cleanup;
+ return false;
if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) {
vshError(ctl, _("Unable to parse integer"));
}
if ((fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
- created = false;
if (errno != EEXIST ||
(fd = open(file, O_WRONLY|O_TRUNC, 0666)) < 0) {
vshError(ctl, _("cannot create %s"), file);
goto cleanup;
}
+ } else {
+ created = true;
}
st = virStreamNew(ctl->conn, 0);
ret = true;
cleanup:
+ VIR_FORCE_CLOSE(fd);
if (ret == false && created)
unlink(file);
if (vol)
virStorageVolFree(vol);
if (st)
virStreamFree(st);
- VIR_FORCE_CLOSE(fd);
return ret;
}