From: VMware, Inc <> Date: Thu, 17 Jun 2010 22:33:41 +0000 (-0700) Subject: lib/file: make file locking a bit more efficient X-Git-Tag: 2010.06.16-268169~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc1e5709041bb4cefb866fe150dc200e32a148c4;p=thirdparty%2Fopen-vm-tools.git lib/file: make file locking a bit more efficient When locking a symbolic link the lock file should go "next" to the symbolic link, not where the link points to. The old code for dealing with this is overkill; performing unnecessary operations to get the job done; improve this. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/file/fileLockPosix.c b/open-vm-tools/lib/file/fileLockPosix.c index 1d4bc0ed2..536b73fd9 100644 --- a/open-vm-tools/lib/file/fileLockPosix.c +++ b/open-vm-tools/lib/file/fileLockPosix.c @@ -988,7 +988,7 @@ FileLockGetExecutionID(void) * points to. * * Results: - * The normalized path + * The normalized path or NULL on error * * Side effects: * None @@ -1000,41 +1000,28 @@ static Unicode FileLockNormalizePath(ConstUnicode filePath) // IN: { Unicode result; - struct stat statbuf; + Unicode fullPath; - if ((Posix_Lstat(filePath, &statbuf) == 0) && - (S_ISLNK(statbuf.st_mode))) { - Unicode fullPath; - Unicode baseDir = NULL; - Unicode fileName = NULL; + Unicode dirName = NULL; + Unicode fileName = NULL; - /* - * The file to be locked is a symbolic path. Place the lock file - * next to the file, not where the symbolic path points to. - */ - - File_GetPathName(filePath, &baseDir, &fileName); - - fullPath = File_FullPath(baseDir); + /* + * If the file to be locked is a symbolic link the lock file belongs next + * to the symbolic link, not "off" where the symbolic link points to. + * Translation: Don't "full path" the entire path of the file to be locked; + * "full path" the dirName of the path, leaving the fileName alone. + */ - if (fullPath == NULL) { - result = NULL; - } else { - result = Unicode_Join(fullPath, DIRSEPS, fileName, NULL); + File_GetPathName(filePath, &dirName, &fileName); - Unicode_Free(fullPath); - } + fullPath = File_FullPath(dirName); - Unicode_Free(baseDir); - Unicode_Free(fileName); - } else { - /* - * The stat failed or the file is not a symbolic link - do a fullpath - * on the argument path to normalize it. - */ + result = (fullPath == NULL) ? NULL : Unicode_Join(fullPath, DIRSEPS, + fileName, NULL); - result = File_FullPath(filePath); - } + Unicode_Free(fullPath); + Unicode_Free(dirName); + Unicode_Free(fileName); return result; }