mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
esx: Unindent unnecessary conditional branch
The positive branch can just return and the huge negative part does not need to be indented an extra level. Best viewed with `-w`. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
6472403c20
commit
697a33b3b3
@ -143,100 +143,100 @@ esxParseVMXFileName(const char *fileName, void *opaque)
|
|||||||
|
|
||||||
if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
|
if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
|
||||||
/* Plain file name, use same directory as for the .vmx file */
|
/* Plain file name, use same directory as for the .vmx file */
|
||||||
result = g_strdup_printf("%s/%s", data->datastorePathWithoutFileName,
|
return g_strdup_printf("%s/%s", data->datastorePathWithoutFileName,
|
||||||
fileName);
|
fileName);
|
||||||
} else {
|
}
|
||||||
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
||||||
"summary.name") < 0 ||
|
|
||||||
esxVI_LookupDatastoreList(data->ctx, propertyNameList,
|
|
||||||
&datastoreList) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Search for datastore by mount path */
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
||||||
for (datastore = datastoreList; datastore;
|
"summary.name") < 0 ||
|
||||||
datastore = datastore->_next) {
|
esxVI_LookupDatastoreList(data->ctx, propertyNameList,
|
||||||
esxVI_DatastoreHostMount_Free(&hostMount);
|
&datastoreList) < 0) {
|
||||||
datastoreName = NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj,
|
/* Search for datastore by mount path */
|
||||||
&hostMount,
|
for (datastore = datastoreList; datastore;
|
||||||
esxVI_Occurrence_RequiredItem) < 0 ||
|
datastore = datastore->_next) {
|
||||||
esxVI_GetStringValue(datastore, "summary.name", &datastoreName,
|
esxVI_DatastoreHostMount_Free(&hostMount);
|
||||||
esxVI_Occurrence_RequiredItem) < 0) {
|
datastoreName = NULL;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = (char *)STRSKIP(fileName, hostMount->mountInfo->path);
|
if (esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj,
|
||||||
|
&hostMount,
|
||||||
if (!tmp)
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
||||||
continue;
|
esxVI_GetStringValue(datastore, "summary.name", &datastoreName,
|
||||||
|
esxVI_Occurrence_RequiredItem) < 0) {
|
||||||
/* Found a match. Strip leading separators */
|
|
||||||
while (*tmp == '/' || *tmp == '\\')
|
|
||||||
++tmp;
|
|
||||||
|
|
||||||
strippedFileName = g_strdup(tmp);
|
|
||||||
|
|
||||||
tmp = strippedFileName;
|
|
||||||
|
|
||||||
/* Convert \ to / */
|
|
||||||
while (*tmp != '\0') {
|
|
||||||
if (*tmp == '\\')
|
|
||||||
*tmp = '/';
|
|
||||||
|
|
||||||
++tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = g_strdup_printf("[%s] %s", datastoreName, strippedFileName);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fallback to direct datastore name match */
|
|
||||||
if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) {
|
|
||||||
copyOfFileName = g_strdup(fileName);
|
|
||||||
|
|
||||||
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
|
|
||||||
if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) ||
|
|
||||||
!(datastoreName = strtok_r(tmp, "/", &saveptr)) ||
|
|
||||||
!(directoryAndFileName = strtok_r(NULL, "", &saveptr))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("File name '%s' doesn't have expected format "
|
|
||||||
"'/vmfs/volumes/<datastore>/<path>'"), fileName);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
esxVI_ObjectContent_Free(&datastoreList);
|
|
||||||
|
|
||||||
if (esxVI_LookupDatastoreByName(data->ctx, datastoreName,
|
|
||||||
NULL, &datastoreList,
|
|
||||||
esxVI_Occurrence_OptionalItem) < 0) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!datastoreList) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("File name '%s' refers to non-existing datastore '%s'"),
|
|
||||||
fileName, datastoreName);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = g_strdup_printf("[%s] %s", datastoreName,
|
|
||||||
directoryAndFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If it's an absolute path outside of a datastore just use it as is */
|
|
||||||
if (!result && *fileName == '/') {
|
|
||||||
/* FIXME: need to deal with Windows paths here too */
|
|
||||||
result = g_strdup(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Could not handle file name '%s'"), fileName);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp = (char *)STRSKIP(fileName, hostMount->mountInfo->path);
|
||||||
|
|
||||||
|
if (!tmp)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Found a match. Strip leading separators */
|
||||||
|
while (*tmp == '/' || *tmp == '\\')
|
||||||
|
++tmp;
|
||||||
|
|
||||||
|
strippedFileName = g_strdup(tmp);
|
||||||
|
|
||||||
|
tmp = strippedFileName;
|
||||||
|
|
||||||
|
/* Convert \ to / */
|
||||||
|
while (*tmp != '\0') {
|
||||||
|
if (*tmp == '\\')
|
||||||
|
*tmp = '/';
|
||||||
|
|
||||||
|
++tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = g_strdup_printf("[%s] %s", datastoreName, strippedFileName);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fallback to direct datastore name match */
|
||||||
|
if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) {
|
||||||
|
copyOfFileName = g_strdup(fileName);
|
||||||
|
|
||||||
|
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
|
||||||
|
if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) ||
|
||||||
|
!(datastoreName = strtok_r(tmp, "/", &saveptr)) ||
|
||||||
|
!(directoryAndFileName = strtok_r(NULL, "", &saveptr))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("File name '%s' doesn't have expected format "
|
||||||
|
"'/vmfs/volumes/<datastore>/<path>'"), fileName);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
esxVI_ObjectContent_Free(&datastoreList);
|
||||||
|
|
||||||
|
if (esxVI_LookupDatastoreByName(data->ctx, datastoreName,
|
||||||
|
NULL, &datastoreList,
|
||||||
|
esxVI_Occurrence_OptionalItem) < 0) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!datastoreList) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("File name '%s' refers to non-existing datastore '%s'"),
|
||||||
|
fileName, datastoreName);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = g_strdup_printf("[%s] %s", datastoreName,
|
||||||
|
directoryAndFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If it's an absolute path outside of a datastore just use it as is */
|
||||||
|
if (!result && *fileName == '/') {
|
||||||
|
/* FIXME: need to deal with Windows paths here too */
|
||||||
|
result = g_strdup(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Could not handle file name '%s'"), fileName);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user