[CalendarServer-changes] [7353] CalendarServer/trunk/twistedcaldav/directory
source_changes at macosforge.org
source_changes at macosforge.org
Thu Apr 21 19:00:32 PDT 2011
Revision: 7353
http://trac.macosforge.org/projects/calendarserver/changeset/7353
Author: sagen at apple.com
Date: 2011-04-21 19:00:30 -0700 (Thu, 21 Apr 2011)
Log Message:
-----------
Fix for issue where modifying resources.xml would end up zeroing out the augments in-memory cache. 9317533
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/directory/augment.py
CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py
Modified: CalendarServer/trunk/twistedcaldav/directory/augment.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/augment.py 2011-04-21 16:55:37 UTC (rev 7352)
+++ CalendarServer/trunk/twistedcaldav/directory/augment.py 2011-04-22 02:00:30 UTC (rev 7353)
@@ -422,7 +422,10 @@
"""
super(AugmentXMLDB, self).refresh()
try:
- self.db = self._parseXML()
+ results = self._parseXML()
+ # Only update the cache if _parseXML( ) returns anything
+ if results:
+ self.db = results
except RuntimeError:
log.error("Failed to parse XML augments file during cache refresh - ignoring")
self.lastCached = time.time()
@@ -437,16 +440,18 @@
self.removeAugmentRecords(self.db.keys())
return succeed(None)
- def _shouldReparse(self, xmlFile):
+ def _shouldReparse(self, xmlFiles):
"""
- Check to see whether the given file has been modified since we last
- parsed it.
+ Check to see whether any of the given files have been modified since
+ we last parsed them.
"""
- oldModTime, oldSize = self.xmlFileStats.get(xmlFile, (0, 0))
- newModTime = os.path.getmtime(xmlFile)
- newSize = os.path.getsize(xmlFile)
- if (oldModTime != newModTime) or (oldSize != newSize):
- return True
+ for xmlFile in xmlFiles:
+ if os.path.exists(xmlFile):
+ oldModTime, oldSize = self.xmlFileStats.get(xmlFile, (0, 0))
+ newModTime = os.path.getmtime(xmlFile)
+ newSize = os.path.getsize(xmlFile)
+ if (oldModTime != newModTime) or (oldSize != newSize):
+ return True
return False
def _parseXML(self):
@@ -456,23 +461,13 @@
If none of the xmlFiles exist, create a default record.
"""
- # Do each file
results = {}
- allMissing = True
+ # If all augments files are missing, return a default record
for xmlFile in self.xmlFiles:
if os.path.exists(xmlFile):
- # Compare previously seen modification time and size of each
- # xml file. If unchanged, skip.
- if self._shouldReparse(xmlFile):
- # Creating a parser does the parse
- XMLAugmentsParser(xmlFile, results)
- newModTime = os.path.getmtime(xmlFile)
- newSize = os.path.getsize(xmlFile)
- self.xmlFileStats[xmlFile] = (newModTime, newSize)
- allMissing = False
-
- if allMissing:
+ break
+ else:
results["Default"] = AugmentRecord(
"Default",
enabled=True,
@@ -480,6 +475,17 @@
enabledForAddressBooks=True,
)
+ # Compare previously seen modification time and size of each
+ # xml file. If all are unchanged, skip.
+ if self._shouldReparse(self.xmlFiles):
+ for xmlFile in self.xmlFiles:
+ if os.path.exists(xmlFile):
+ # Creating a parser does the parse
+ XMLAugmentsParser(xmlFile, results)
+ newModTime = os.path.getmtime(xmlFile)
+ newSize = os.path.getsize(xmlFile)
+ self.xmlFileStats[xmlFile] = (newModTime, newSize)
+
return results
class AugmentADAPI(AugmentDB, AbstractADBAPIDatabase):
Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py 2011-04-21 16:55:37 UTC (rev 7352)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py 2011-04-22 02:00:30 UTC (rev 7353)
@@ -281,10 +281,20 @@
newxmlfile = FilePath(self.mktemp())
FilePath(xmlFile).copyTo(newxmlfile)
db = AugmentXMLDB((newxmlfile.path,))
- self.assertFalse(db._shouldReparse(newxmlfile.path)) # No need to parse
+ self.assertFalse(db._shouldReparse([newxmlfile.path])) # No need to parse
newxmlfile.setContent("") # Change the file
- self.assertTrue(db._shouldReparse(newxmlfile.path)) # Need to parse
+ self.assertTrue(db._shouldReparse([newxmlfile.path])) # Need to parse
+ def test_refresh(self):
+ """
+ Ensure that a refresh without any file changes doesn't zero out the
+ cache
+ """
+ dbxml = AugmentXMLDB((xmlFile,))
+ keys = dbxml.db.keys()
+ dbxml.refresh()
+ self.assertEquals(keys, dbxml.db.keys())
+
class AugmentSqliteTests(AugmentTests, AugmentTestsMixin):
def _db(self, dbpath=None):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110421/84867857/attachment.html>
More information about the calendarserver-changes
mailing list