提交 902aaabb 编写于 作者: M Matthias Bolte 提交者: Daniel Veillard

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
上级 6b50bbea
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册