[CalendarServer-changes] [3748] CalendarServer/branches/users/sagen/migration-3735/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 25 14:46:42 PST 2009
Revision: 3748
http://trac.macosforge.org/projects/calendarserver/changeset/3748
Author: sagen at apple.com
Date: 2009-02-25 14:46:42 -0800 (Wed, 25 Feb 2009)
Log Message:
-----------
Upon modifying a resource, update its getcontentmd5 xattr, as well as the collection's getctag xattr
Modified Paths:
--------------
CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/test_upgrade.py
CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/util.py
CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/upgrade.py
Modified: CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/test_upgrade.py
===================================================================
--- CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/test_upgrade.py 2009-02-25 18:45:33 UTC (rev 3747)
+++ CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/test_upgrade.py 2009-02-25 22:46:42 UTC (rev 3748)
@@ -347,12 +347,12 @@
"@contents" : event01_after,
"@xattrs" :
{
- # no md5 attr
+ md5Attr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<getcontentmd5 xmlns='http://twistedmatrix.com/xml_namespace/dav/'>967eac8e6cc69b43fb820e8cf438d8e7</getcontentmd5>\r\n"),
},
},
"@xattrs" :
{
- # no CTAG
+ cTagAttr : isValidCTag, # method below
},
},
"inbox" :
@@ -462,6 +462,10 @@
{
"@contents" : event01_after,
},
+ "@xattrs" :
+ {
+ cTagAttr : isValidCTag, # method below
+ },
},
"inbox" :
{
@@ -570,13 +574,13 @@
"@contents" : event01_after,
"@xattrs" :
{
- # No md5 attr
+ md5Attr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<getcontentmd5 xmlns='http://twistedmatrix.com/xml_namespace/dav/'>967eac8e6cc69b43fb820e8cf438d8e7</getcontentmd5>\r\n"),
},
},
"@xattrs" :
{
"ignore" : "extra",
- # No ctag attr
+ cTagAttr : isValidCTag, # method below
},
},
"inbox" :
@@ -610,6 +614,120 @@
self.assertTrue(self.verifyHierarchy(root, after))
+ def test_calendarsUpgradeWithNoChange(self):
+ """
+ Verify that calendar homes in the /calendars/__uids__/XX/YY/<guid>/
+ form which require no changes are untouched
+ """
+
+ self.setUpXMLDirectory()
+ directory = getDirectory()
+
+ before = {
+ "calendars" :
+ {
+ "__uids__" :
+ {
+ "64" :
+ {
+ "23" :
+ {
+ "6423F94A-6B76-4A3A-815B-D52CFD77935D" :
+ {
+ "calendar" :
+ {
+ "1E238CA1-3C95-4468-B8CD-C8A399F78C72.ics" :
+ {
+ "@contents" : event01_after,
+ "@xattrs" :
+ {
+ md5Attr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<getcontentmd5 xmlns='http://twistedmatrix.com/xml_namespace/dav/'>967eac8e6cc69b43fb820e8cf438d8e7</getcontentmd5>\r\n"),
+ },
+ },
+ "@xattrs" :
+ {
+ "ignore" : "extra",
+ cTagAttr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<getctag xmlns='http://calendarserver.org/ns/'>2009-02-25 14:34:34.703093</getctag>\r\n"),
+ },
+ },
+ "inbox" :
+ {
+ "@xattrs" :
+ {
+ # Zlib compressed XML
+ freeBusyAttr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar/</href>\r\n</calendar-free-busy-set>\r\n"),
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ CalendarUserProxyDatabase.dbFilename :
+ {
+ "@contents" : "",
+ }
+ }
+
+ after = {
+ ".calendarserver_version" :
+ {
+ "@contents" : "1",
+ },
+ "calendars" :
+ {
+ "__uids__" :
+ {
+ "64" :
+ {
+ "23" :
+ {
+ "6423F94A-6B76-4A3A-815B-D52CFD77935D" :
+ {
+ "calendar" :
+ {
+ "1E238CA1-3C95-4468-B8CD-C8A399F78C72.ics" :
+ {
+ "@contents" : event01_after,
+ "@xattrs" :
+ {
+ md5Attr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<getcontentmd5 xmlns='http://twistedmatrix.com/xml_namespace/dav/'>967eac8e6cc69b43fb820e8cf438d8e7</getcontentmd5>\r\n"),
+ },
+ },
+ "@xattrs" :
+ {
+ "ignore" : "extra",
+ cTagAttr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<getctag xmlns='http://calendarserver.org/ns/'>2009-02-25 14:34:34.703093</getctag>\r\n"),
+ },
+ },
+ "inbox" :
+ {
+ "@xattrs" :
+ {
+ freeBusyAttr : zlib.compress("<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar/</href>\r\n</calendar-free-busy-set>\r\n"),
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ CalendarUserProxyDatabase.dbFilename :
+ {
+ "@contents" : "",
+ }
+ }
+
+ root = self.createHierarchy(before)
+
+ config.DocumentRoot = root
+ config.DataRoot = root
+
+ upgradeData(config)
+ self.assertTrue(self.verifyHierarchy(root, after))
+
+
+
event01_before = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 3.0//EN
@@ -693,3 +811,18 @@
END:VCALENDAR
""".replace("\n", "\r\n")
+
+def isValidCTag(value):
+ """
+ Since ctag is generated from datetime.now(), let's make sure that at
+ least the value is zlib compressed XML
+ """
+ try:
+ value = zlib.decompress(value)
+ except zlib.error:
+ return False
+ try:
+ doc = davxml.WebDAVDocument.fromString(value)
+ return True
+ except ValueError:
+ return False
Modified: CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/util.py
===================================================================
--- CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/util.py 2009-02-25 18:45:33 UTC (rev 3747)
+++ CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/test/util.py 2009-02-25 22:46:42 UTC (rev 3748)
@@ -104,11 +104,16 @@
if childStructure.has_key("@xattrs"):
xattrs = childStructure["@xattrs"]
for attr, value in xattrs.iteritems():
- try:
- if xattr.getxattr(childPath, attr) != value:
+ if isinstance(value, str):
+ try:
+ if xattr.getxattr(childPath, attr) != value:
+ return False
+ except:
return False
- except:
- return False
+ else: # method
+ if not value(xattr.getxattr(childPath, attr)):
+ return False
+
for attr, value in xattr.xattr(childPath).iteritems():
if attr not in xattrs:
return False
Modified: CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/upgrade.py 2009-02-25 18:45:33 UTC (rev 3747)
+++ CalendarServer/branches/users/sagen/migration-3735/twistedcaldav/upgrade.py 2009-02-25 22:46:42 UTC (rev 3748)
@@ -25,7 +25,7 @@
from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
from twistedcaldav import caldavxml
from calendarserver.tools.util import getDirectory, dummyDirectoryRecord
-import xattr, itertools, os, zlib
+import xattr, itertools, os, zlib, hashlib, datetime
from zlib import compress, decompress
from cPickle import loads as unpickle, PicklingError, UnpicklingError
@@ -88,6 +88,8 @@
def upgradeCalendarCollection(calPath, directory):
+ collectionUpdated = False
+
for resource in os.listdir(calPath):
if resource.startswith("."):
@@ -99,9 +101,8 @@
# Skip directories
continue
- resPathTmp = "%s.tmp" % resPath
-
log.info("Processing: %s" % (resPath,))
+ needsRewrite = False
with open(resPath) as res:
data = res.read()
@@ -109,6 +110,7 @@
data, fixed = fixBadQuotes(data)
if fixed:
log.info("Fixing bad quotes in %s" % (resPath,))
+ needsRewrite = True
except Exception, e:
log.error("Error while fixing bad quotes in %s: %s" %
(resPath, e))
@@ -118,23 +120,29 @@
data, fixed = normalizeCUAddrs(data, directory)
if fixed:
log.info("Normalized CUAddrs in %s" % (resPath,))
+ needsRewrite = True
except Exception, e:
log.error("Error while normalizing %s: %s" %
(resPath, e))
raise
- # Write to a new file, then rename it over the old one
- with open(resPathTmp, "w") as res:
- res.write(data)
- os.rename(resPathTmp, resPath)
+ if needsRewrite:
+ with open(resPath, "w") as res:
+ res.write(data)
+ md5value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<getcontentmd5 xmlns='http://twistedmatrix.com/xml_namespace/dav/'>%s</getcontentmd5>\r\n" % (hashlib.md5(data).hexdigest(),)
+ md5value = zlib.compress(md5value)
+ xattr.setxattr(resPath, "WebDAV:{http:%2F%2Ftwistedmatrix.com%2Fxml_namespace%2Fdav%2F}getcontentmd5", md5value)
- # Remove the ctag xattr from the calendar collection
- for attr, value in xattr.xattr(calPath).iteritems():
- if attr == "WebDAV:{http:%2F%2Fcalendarserver.org%2Fns%2F}getctag":
- xattr.removexattr(calPath, attr, value)
+ collectionUpdated = True
+ if collectionUpdated:
+ ctagValue = "<?xml version='1.0' encoding='UTF-8'?>\r\n<getctag xmlns='http://calendarserver.org/ns/'>%s</getctag>\r\n" % (str(datetime.datetime.now()),)
+ ctagValue = zlib.compress(ctagValue)
+ xattr.setxattr(calPath, "WebDAV:{http:%2F%2Fcalendarserver.org%2Fns%2F}getctag", ctagValue)
+
+
def upgradeCalendarHome(homePath, directory):
log.info("Upgrading calendar home: %s" % (homePath,))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090225/5ec8cf02/attachment-0001.html>
More information about the calendarserver-changes
mailing list