From df18c2c2c3e7dde4478ee68a5f4a96600a3d07a2 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 5 Jan 2018 14:47:14 -0800 Subject: [PATCH] Allow copying of object policy within the same container ObjLib_CloneExtParams is currently not allowing copying of policy from parent to child/clone object on VSAN. This is because the copy policy check is based on unique filesystem ID, which will be different for parent and child on VSAN because they will mostly be created on same container but different namespace. This change uses VCFS root instead of namespace UUID to make the comparison on VSAN. Bonus fix: File_FullPath is now fixed to work for any combination of ancestor path being present. Currently it only works if either the given path exists, or when only the last component of the path does not exist. And since this fix relies on finding the VCFS root of both parent and child (parent is present but child is not), ObjLibPathToVCFSRoot has been modified to rely on File_FullPath in addition to Util_GetCanonicalPath if the path does not exist. --- open-vm-tools/lib/file/filePosix.c | 36 +++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/open-vm-tools/lib/file/filePosix.c b/open-vm-tools/lib/file/filePosix.c index 6f45d8465..55602b59a 100644 --- a/open-vm-tools/lib/file/filePosix.c +++ b/open-vm-tools/lib/file/filePosix.c @@ -574,11 +574,12 @@ File_StripFwdSlashes(const char *pathName) // IN: * path of "." is the current working directory, ".." is parent * directory and so on. If the path is NULL or "", this routine * returns the current working directory. - * There are mainly two use cases for this function. To find the - * canonical path of a file or directory that exists, or when we - * are about to create a child in an existing parent directory. - * For other uses cases, this routine is not guaranteed to return - * a canonical path. + * + * On FreeBSD and Sun platforms, this routine will only work if + * the path exists, or when we are about to create a child in an + * existing parent directory. This is because on these platforms, + * we cannot rely on finding existing ancestor and such because + * those functions are not compiled. * * Results: * NULL if error (reported to the user) @@ -619,18 +620,41 @@ File_FullPath(const char *pathName) // IN: if (ret == NULL) { char *dir; char *file; +#if defined(__FreeBSD__) || defined(sun) char *realDir; +#else + char *ancestorPath; + char *ancestorRealPath; +#endif File_GetPathName(path, &dir, &file); +#if defined(__FreeBSD__) || defined(sun) realDir = Posix_RealPath(dir); if (realDir == NULL) { realDir = File_StripFwdSlashes(dir); } ret = Unicode_Join(realDir, DIRSEPS, file, NULL); + Posix_Free(realDir); +#else + ancestorPath = FilePosixNearestExistingAncestor(dir); + ancestorRealPath = Posix_RealPath(ancestorPath); + + /* + * Check if the ancestor was deleted before we could compute its + * realPath + */ + if (ancestorRealPath == NULL) { + ret = File_StripFwdSlashes(path); + } else { + ret = File_PathJoin(ancestorRealPath, path + strlen(ancestorPath)); + Posix_Free(ancestorRealPath); + } + + Posix_Free(ancestorPath); +#endif Posix_Free(dir); Posix_Free(file); - Posix_Free(realDir); } Posix_Free(path); -- 2.47.3