ESX: Fix VMX path parsing and URL encoding

* src/esx/esx_driver.c: handle spaces in VMX file path and use a
  virBuffer to encode spaces correctly in the resulting URL
* src/esx/esx_vi.c: include the URL in the error message in case
  of a download error
This commit is contained in:
Matthias Bolte 2009-09-04 17:55:55 +02:00 committed by Daniel Veillard
parent 6b50bbea00
commit 902aaabb11
2 changed files with 15 additions and 6 deletions

View File

@ -2015,6 +2015,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
const char *vmPathName = NULL;
char *datastoreName = NULL;
char *vmxPath = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *url = NULL;
char *vmx = NULL;
virDomainDefPtr def = NULL;
@ -2052,21 +2053,28 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
}
/* expected format: "[<datastoreName>] <vmxPath>" */
if (sscanf(vmPathName, "[%a[^]%]] %as", &datastoreName, &vmxPath) != 2) {
if (sscanf(vmPathName, "[%a[^]%]] %a[^\n]", &datastoreName, &vmxPath) != 2) {
ESX_ERROR(domain->conn, VIR_ERR_OPERATION_INVALID,
"'config.files.vmPathName' property '%s' doesn't have "
"expected format '[<datastore>] <vmx>'", vmPathName);
goto failure;
}
if (virAsprintf(&url, "%s://%s:%d/folder/%s?dcPath=%s&dsName=%s",
priv->transport, domain->conn->uri->server,
domain->conn->uri->port, vmxPath,
priv->host->datacenter->value, datastoreName) < 0) {
virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
domain->conn->uri->server, domain->conn->uri->port);
virBufferURIEncodeString(&buffer, vmxPath);
virBufferAddLit(&buffer, "?dcPath=");
virBufferURIEncodeString(&buffer, priv->host->datacenter->value);
virBufferAddLit(&buffer, "&dsName=");
virBufferURIEncodeString(&buffer, datastoreName);
if (virBufferError(&buffer)) {
virReportOOMError(domain->conn);
goto failure;
}
url = virBufferContentAndReset(&buffer);
if (esxVI_Context_Download(domain->conn, priv->host, url, &vmx) < 0) {
goto failure;
}

View File

@ -442,7 +442,8 @@ esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx, const char *url,
if (responseCode != 200) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"HTTP response code %d", (int)responseCode);
"HTTP response code %d while trying to download '%s'",
(int)responseCode, url);
goto failure;
}