]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: make file locking a bit more efficient
authorVMware, Inc <>
Thu, 17 Jun 2010 22:33:41 +0000 (15:33 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 17 Jun 2010 22:33:41 +0000 (15:33 -0700)
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 <mvanzin@vmware.com>
open-vm-tools/lib/file/fileLockPosix.c

index 1d4bc0ed2b02ac5b189541bf78a105b5c7d1f592..536b73fd9033f61dc831e37d8fa07e70c5229559 100644 (file)
@@ -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;
 }