mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
util: qemu: Don't generate any extra commas in virQEMUBuildCommandLineJSON
The function would generate a leading comma. Let the callers properly add commas by formatting the commas at the end and trimming the trailing one.
This commit is contained in:
parent
b7eef33df2
commit
ca620e35ea
@ -66,10 +66,10 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key,
|
|||||||
end = virBitmapLastSetBit(bitmap) + 1;
|
end = virBitmapLastSetBit(bitmap) + 1;
|
||||||
|
|
||||||
if (end - 1 > pos) {
|
if (end - 1 > pos) {
|
||||||
virBufferAsprintf(buf, ",%s=%zd-%zd", key, pos, end - 1);
|
virBufferAsprintf(buf, "%s=%zd-%zd,", key, pos, end - 1);
|
||||||
pos = end;
|
pos = end;
|
||||||
} else {
|
} else {
|
||||||
virBufferAsprintf(buf, ",%s=%zd", key, pos);
|
virBufferAsprintf(buf, "%s=%zd,", key, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,19 +125,20 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
|
|||||||
|
|
||||||
switch ((virJSONType) value->type) {
|
switch ((virJSONType) value->type) {
|
||||||
case VIR_JSON_TYPE_STRING:
|
case VIR_JSON_TYPE_STRING:
|
||||||
virBufferAsprintf(buf, ",%s=", key);
|
virBufferAsprintf(buf, "%s=", key);
|
||||||
virQEMUBuildBufferEscapeComma(buf, value->data.string);
|
virQEMUBuildBufferEscapeComma(buf, value->data.string);
|
||||||
|
virBufferAddLit(buf, ",");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_JSON_TYPE_NUMBER:
|
case VIR_JSON_TYPE_NUMBER:
|
||||||
virBufferAsprintf(buf, ",%s=%s", key, value->data.number);
|
virBufferAsprintf(buf, "%s=%s,", key, value->data.number);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_JSON_TYPE_BOOLEAN:
|
case VIR_JSON_TYPE_BOOLEAN:
|
||||||
if (value->data.boolean)
|
if (value->data.boolean)
|
||||||
virBufferAsprintf(buf, ",%s=yes", key);
|
virBufferAsprintf(buf, "%s=yes,", key);
|
||||||
else
|
else
|
||||||
virBufferAsprintf(buf, ",%s=no", key);
|
virBufferAsprintf(buf, "%s=no,", key);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -196,7 +197,12 @@ virQEMUBuildCommandLineJSON(const virJSONValue *value,
|
|||||||
virBufferPtr buf,
|
virBufferPtr buf,
|
||||||
virQEMUBuildCommandLineJSONArrayFormatFunc array)
|
virQEMUBuildCommandLineJSONArrayFormatFunc array)
|
||||||
{
|
{
|
||||||
return virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, array, false);
|
if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, array, false) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
virBufferTrim(buf, ",", -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -208,7 +214,7 @@ virQEMUBuildObjectCommandlineFromJSON(const char *type,
|
|||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "%s,id=%s", type, alias);
|
virBufferAsprintf(&buf, "%s,id=%s,", type, alias);
|
||||||
|
|
||||||
if (virQEMUBuildCommandLineJSON(props, &buf,
|
if (virQEMUBuildCommandLineJSON(props, &buf,
|
||||||
virQEMUBuildCommandLineJSONArrayBitmap) < 0)
|
virQEMUBuildCommandLineJSONArrayBitmap) < 0)
|
||||||
|
@ -37,7 +37,6 @@ testQemuCommandBuildFromJSON(const void *opaque)
|
|||||||
{
|
{
|
||||||
const testQemuCommandBuildObjectFromJSONData *data = opaque;
|
const testQemuCommandBuildObjectFromJSONData *data = opaque;
|
||||||
virJSONValuePtr val = NULL;
|
virJSONValuePtr val = NULL;
|
||||||
char *expect = NULL;
|
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -47,10 +46,6 @@ testQemuCommandBuildFromJSON(const void *opaque)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->expectprops &&
|
|
||||||
virAsprintf(&expect, ",%s", data->expectprops) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (virQEMUBuildCommandLineJSON(val, &buf,
|
if (virQEMUBuildCommandLineJSON(val, &buf,
|
||||||
virQEMUBuildCommandLineJSONArrayBitmap) < 0) {
|
virQEMUBuildCommandLineJSONArrayBitmap) < 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -61,10 +56,10 @@ testQemuCommandBuildFromJSON(const void *opaque)
|
|||||||
|
|
||||||
result = virBufferContentAndReset(&buf);
|
result = virBufferContentAndReset(&buf);
|
||||||
|
|
||||||
if (STRNEQ_NULLABLE(expect, result)) {
|
if (STRNEQ_NULLABLE(data->expectprops, result)) {
|
||||||
fprintf(stderr, "\nFailed to create object string. "
|
fprintf(stderr, "\nFailed to create object string. "
|
||||||
"\nExpected:\n'%s'\nGot:\n'%s'",
|
"\nExpected:\n'%s'\nGot:\n'%s'",
|
||||||
NULLSTR(expect), NULLSTR(result));
|
NULLSTR(data->expectprops), NULLSTR(result));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +67,6 @@ testQemuCommandBuildFromJSON(const void *opaque)
|
|||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(val);
|
virJSONValueFree(val);
|
||||||
VIR_FREE(result);
|
VIR_FREE(result);
|
||||||
VIR_FREE(expect);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user