[Zope3-checkins] CVS: Zope3/src/zope/app/fssync - committer.py:1.10

Guido van Rossum guido@python.org
Thu, 5 Jun 2003 16:52:45 -0400


Update of /cvs-repository/Zope3/src/zope/app/fssync
In directory cvs.zope.org:/tmp/cvs-serv30651

Modified Files:
	committer.py 
Log Message:
Three important fixes, not reflected in unit tests alas. :-(

- There was a call to objectName() in an unconditional try/except, but
  objectName was never imported, so the publish() call never happened.

- When deciding whether to update or not, compare the new data with
  the old data from the "original" file, not to the current data from
  the live object.  The old way would overwrite the DC metadata with
  the old DC metadata after it had been updated to reflect the
  modification.

- Don't call setBody() if the entry specifies no factory; this is the
  case for the Default adapter, whose setBody() doesn't work "because
  the object representation is a pickle."


=== Zope3/src/zope/app/fssync/committer.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/fssync/committer.py:1.9	Thu Jun  5 14:50:57 2003
+++ Zope3/src/zope/app/fssync/committer.py	Thu Jun  5 16:52:45 2003
@@ -33,7 +33,7 @@
 from zope.app.interfaces.annotation import IAnnotations
 from zope.app.interfaces.container import IContainer, IZopeContainer
 from zope.app.fssync.classes import Default
-from zope.app.traversing import getPath, traverseName
+from zope.app.traversing import getPath, traverseName, objectName
 from zope.app.interfaces.file import IFileFactory, IDirectoryFactory
 from zope.app.event import publish
 from zope.app.event.objectevent import ObjectCreatedEvent
@@ -290,10 +290,15 @@
             if adapter.typeIdentifier() != entry.get("type"):
                 create_object(container, name, entry, fspath, replace=True)
             else:
-                curdata = adapter.getBody()
+                olddata = read_file(fsutil.getoriginal(fspath))
                 newdata = read_file(fspath)
-                if newdata != curdata:
-                    adapter.setBody(newdata)
+                if newdata != olddata:
+                    if not entry.get("factory"):
+                        # If there's no factory, we can't call setBody()
+                        create_object(container, name, entry, fspath, True)
+                        obj = traverseName(container, name)
+                    else:
+                        adapter.setBody(newdata)
                     # Now publish an event, but not for annotations or
                     # extras.  To know which case we have, see if
                     # objectName() works.  XXX This is a hack.