From: Michal Privoznik <[email protected]>

The esxParseVMXFileName() function parses path to a disk image
trying to replace some "known" patterns (e.g. datastore paths).
A simple filename is treated as a path relative to .vmx file. But
disk images (and thus filenames) can be in a subdirectory,
relative to the .vmx file. For instance:

  subfolder/disk.vmdk

Adapt our parser to this fact.

Resolves: https://issues.redhat.com/browse/RHEL-122751
Signed-off-by: Michal Privoznik <[email protected]>
---
 src/esx/esx_driver.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 6452a33b7c..9f965811b1 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -72,9 +72,11 @@ esxFreePrivate(esxPrivate **priv)
  * Parse a file name from a .vmx file and convert it to datastore path format
  * if possible. A .vmx file can contain file names in various formats:
  *
- * - A single name referencing a file in the same directory as the .vmx file:
+ * - A single name referencing a file in the same directory as the .vmx file,
+ *   or in a subdirectory:
  *
  *     test1.vmdk
+ *     subdir/test2.vmdk
  *
  * - An absolute file name referencing a file in a datastore that is mounted at
  *   /vmfs/volumes/<datastore>:
@@ -106,8 +108,9 @@ esxFreePrivate(esxPrivate **priv)
  *
  * Firstly this functions checks if the given file name contains a separator.
  * If it doesn't then the referenced file is in the same directory as the .vmx
- * file. The datastore name and directory of the .vmx file are passed to this
- * function via the opaque parameter by the caller of virVMXParseConfig.
+ * file, or in a subdirectory. The datastore name and directory of the .vmx
+ * file are passed to this function via the opaque parameter by the caller of
+ * virVMXParseConfig.
  *
  * Otherwise query for all known datastores and their mount directories. Then
  * try to find a datastore with a mount directory that is a prefix to the given
@@ -138,7 +141,7 @@ esxParseVMXFileName(const char *fileName,
 
     *out = NULL;
 
-    if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
+    if (*fileName != '/' && !strchr(fileName, '\\')) {
         /* Plain file name, use same directory as for the .vmx file */
         *out = g_strdup_printf("%s/%s", data->datastorePathWithoutFileName,
                                fileName);
-- 
2.51.0

Reply via email to