mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
esx: Rework datastore path parsing and handling
Instead of splitting the path part of a datastore path into directory and file name, keep this in one piece. An example: "[datastore] directory/file" was split into this before: datastoreName = "datastore" directoryName = "directory" fileName = "file" Now it's split into this: datastoreName = "datastore" directoryName = "directory" directoryAndFileName = "directory/file" This simplifies code using esxUtil_ParseDatastorePath, because directoryAndFileName is used more often than fileName. Also the old approach expected the datastore path to reference an actual file, but this isn't always correct, especially when listing volumes. In that case esxUtil_ParseDatastorePath is used to parse a path that references a directory. This fails for a vpx:// connection because the vCenter returns directory paths with a trailing '/'. The new approach is robust against this and the actual decision if the datastore path should reference a file or a directory is up to the caller of esxUtil_ParseDatastorePath. Update the tests accordingly.
This commit is contained in:
1 parent
2af93cd43c
commit
847689129c
7 files changed
+156
-160
No files matched your search
+6
-13
@@ -148,24 +148,18 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
bool success = false;
|
||||
char *datastoreName = NULL;
|
||||
char *directoryName = NULL;
|
||||
char *fileName = NULL;
|
||||
char *directoryAndFileName = NULL;
|
||||
char *absolutePath = NULL;
|
||||
|
||||
if (STRPREFIX(src, "[")) {
|
||||
/* Found potential datastore path */
|
||||
if (esxUtil_ParseDatastorePath(src, &datastoreName, &directoryName,
|
||||
&fileName) < 0) {
|
||||
if (esxUtil_ParseDatastorePath(src, &datastoreName, NULL,
|
||||
&directoryAndFileName) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (directoryName == NULL) {
|
||||
virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", datastoreName,
|
||||
fileName);
|
||||
} else {
|
||||
virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s/%s", datastoreName,
|
||||
directoryName, fileName);
|
||||
}
|
||||
virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", datastoreName,
|
||||
directoryAndFileName);
|
||||
} else if (STRPREFIX(src, "/")) {
|
||||
/* Found absolute path */
|
||||
absolutePath = strdup(src);
|
||||
@@ -182,8 +176,7 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
|
||||
}
|
||||
|
||||
VIR_FREE(datastoreName);
|
||||
VIR_FREE(directoryName);
|
||||
VIR_FREE(fileName);
|
||||
VIR_FREE(directoryAndFileName);
|
||||
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user