You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2010/08/14 14:32:04 UTC

svn commit: r985477 - /subversion/branches/performance/subversion/libsvn_subr/io.c

Author: stefan2
Date: Sat Aug 14 12:32:04 2010
New Revision: 985477

URL: http://svn.apache.org/viewvc?rev=985477&view=rev
Log:
Eliminate all file system access in get_default_file_perms() for all but the first execution.

The only downside is that we don't detect FS permission changes made while the 
(client) process runs. Because such changes would cause race conditions and file I/O
errors anyway, we are not make things worse by omitting those tests.

* subversion/libsvn_subr/io.c
  (get_default_file_perms): store result in a singleton in the first run and bypass
  the FS access in all later runs

Modified:
    subversion/branches/performance/subversion/libsvn_subr/io.c

Modified: subversion/branches/performance/subversion/libsvn_subr/io.c
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/io.c?rev=985477&r1=985476&r2=985477&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/io.c (original)
+++ subversion/branches/performance/subversion/libsvn_subr/io.c Sat Aug 14 12:32:04 2010
@@ -1297,30 +1297,47 @@ reown_file(const char *path,
 static svn_error_t *
 get_default_file_perms(apr_fileperms_t *perms, apr_pool_t *scratch_pool)
 {
-  apr_finfo_t finfo;
-  apr_file_t *fd;
+  /* the default permissions as read from the temp folder */
+  static apr_fileperms_t default_perms = 0;
 
-  /* Get the perms for a newly created file to find out what bits
-     should be set.
+  /* Technically, this "racy": Multiple threads may use enter here and
+     try to figure out the default permisission concurrently. That's fine
+     since they will end up with the same results. Even more technical,
+     apr_fileperms_t is an atomic type on 32+ bit machines.
+   */
+  if (default_perms == 0)
+    {
+      apr_finfo_t finfo;
+      apr_file_t *fd;
 
-     NOTE: normally del_on_close can be problematic because APR might
-       delete the file if we spawned any child processes. In this case,
-       the lifetime of this file handle is about 3 lines of code, so
-       we can safely use del_on_close here.
-
-     NOTE: not so fast, shorty. if some other thread forks off a child,
-       then the APR cleanups run, and the file will disappear. sigh.
-
-     Using svn_io_open_uniquely_named() here because other tempfile
-     creation functions tweak the permission bits of files they create.
-  */
-  SVN_ERR(svn_io_open_uniquely_named(&fd, NULL, NULL, "svn-tempfile", ".tmp",
-                                     svn_io_file_del_on_pool_cleanup,
-                                     scratch_pool, scratch_pool));
-  SVN_ERR(svn_io_file_info_get(&finfo, APR_FINFO_PROT, fd, scratch_pool));
-  SVN_ERR(svn_io_file_close(fd, scratch_pool));
+      /* Get the perms for a newly created file to find out what bits
+        should be set.
+
+        NOTE: normally del_on_close can be problematic because APR might
+          delete the file if we spawned any child processes. In this case,
+          the lifetime of this file handle is about 3 lines of code, so
+          we can safely use del_on_close here.
+
+        NOTE: not so fast, shorty. if some other thread forks off a child,
+          then the APR cleanups run, and the file will disappear. sigh.
+
+        Using svn_io_open_uniquely_named() here because other tempfile
+        creation functions tweak the permission bits of files they create.
+      */
+      SVN_ERR(svn_io_open_uniquely_named(&fd, NULL, NULL, "svn-tempfile", ".tmp",
+                                        svn_io_file_del_on_pool_cleanup,
+                                        scratch_pool, scratch_pool));
+      SVN_ERR(svn_io_file_info_get(&finfo, APR_FINFO_PROT, fd, scratch_pool));
+      SVN_ERR(svn_io_file_close(fd, scratch_pool));
+
+      *perms = finfo.protection;
+      default_perms = finfo.protection;
+    }
+  else
+    {
+      *perms = default_perms;
+    }
 
-  *perms = finfo.protection;
   return SVN_NO_ERROR;
 }