[Zope3-checkins] CVS: Zope3/src/zope/fssync - metadata.py:1.3

Guido van Rossum guido@python.org
Wed, 4 Jun 2003 15:01:08 -0400


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

Modified Files:
	metadata.py 
Log Message:
Change flushkey() so that the Entries.xml file is never deleted.
Instead, an empty dict may be written to it.
(This is because deleting the file may delete the last *file* in a tree,
which makes it invisible when snarfed.)

=== Zope3/src/zope/fssync/metadata.py 1.2 => 1.3 ===
--- Zope3/src/zope/fssync/metadata.py:1.2	Tue May 13 12:15:21 2003
+++ Zope3/src/zope/fssync/metadata.py	Wed Jun  4 15:00:37 2003
@@ -106,27 +106,20 @@
 
     def flushkey(self, key):
         entries = self.cache[key]
-        todelete = [name for name, entry in entries.iteritems() if not entry]
-        for name in todelete:
-            del entries[name]
         if entries != self.originals[key]:
+            # Make a copy containing only the "live" (non-empty) entries
+            live = {}
+            for name, entry in entries.iteritems():
+                if entry:
+                    live[name] = entry
             zdir = join(key, "@@Zope")
             efile = join(zdir, "Entries.xml")
-            if not entries:
-                if isfile(efile):
-                    os.remove(efile)
-                    if exists(zdir):
-                        try:
-                            os.rmdir(zdir)
-                        except os.error:
-                            pass
-            else:
-                data = dumps(entries)
-                if not exists(zdir):
-                    os.makedirs(zdir)
-                f = open(efile, "w")
-                try:
-                    f.write(data)
-                finally:
-                    f.close()
+            data = dumps(live)
+            if not exists(zdir):
+                os.makedirs(zdir)
+            f = open(efile, "w")
+            try:
+                f.write(data)
+            finally:
+                f.close()
             self.originals[key] = copy.deepcopy(entries)