[CalendarServer-changes] [14073] CalendarServer/trunk/twistedcaldav/timezones.py

source_changes at macosforge.org source_changes at macosforge.org
Sat Oct 11 07:13:58 PDT 2014


Revision: 14073
          http://trac.calendarserver.org//changeset/14073
Author:   cdaboo at apple.com
Date:     2014-10-11 07:13:58 -0700 (Sat, 11 Oct 2014)
Log Message:
-----------
Use file system lock to prevent concurrency problems.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/timezones.py

Modified: CalendarServer/trunk/twistedcaldav/timezones.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/timezones.py	2014-10-11 01:21:14 UTC (rev 14072)
+++ CalendarServer/trunk/twistedcaldav/timezones.py	2014-10-11 14:13:58 UTC (rev 14073)
@@ -19,6 +19,7 @@
 from twext.python.log import Logger
 
 from twisted.python.filepath import FilePath
+from twisted.python.lockfile import FilesystemLock
 
 from twistedcaldav.config import config
 
@@ -143,7 +144,7 @@
     @staticmethod
     def copyPackage(title):
         """
-        Copy package directory to db path using a temporary sibling to avoid potential
+        Copy package directory to db path using a file lock to avoid potential
         concurrency race conditions.
 
         @param title: string to use in log entry
@@ -151,22 +152,23 @@
         """
         dbpath = FilePath(TimezoneCache.getDBPath())
         pkgpath = TimezoneCache.FilteredFilePath(TimezoneCache._getPackageDBPath())
-        log.info(
-            "{title} timezones from {pkg} to {to}",
-            title=title,
-            pkg=pkgpath.path,
-            to=dbpath.path
-        )
 
-        # Use temp directory to copy to first
-        temp = dbpath.temporarySibling()
-        pkgpath.copyFilteredDirectoryTo(temp)
+        lockfile = FilesystemLock(dbpath.path + ".lock")
+        result = lockfile.lock()
+        try:
+            if result and not dbpath.exists():
+                log.info(
+                    "{title} timezones from {pkg} to {to}",
+                    title=title,
+                    pkg=pkgpath.path,
+                    to=dbpath.path
+                )
 
-        # Move to actual path if it stll does not exist
-        if not dbpath.exists():
-            temp.moveTo(dbpath)
-        else:
-            temp.remove()
+                # Copy over the entire package
+                pkgpath.copyFilteredDirectoryTo(dbpath)
+        finally:
+            if result:
+                lockfile.unlock()
 
 
     @staticmethod
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141011/af0327be/attachment.html>


More information about the calendarserver-changes mailing list