[Zope3-checkins] CVS: Zope3/src/zope/fssync - fsmerger.py:1.8

Guido van Rossum guido@python.org
Tue, 3 Jun 2003 16:01:37 -0400


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

Modified Files:
	fsmerger.py 
Log Message:
When creating a local directory, also add @@Zope and
@@Zope/Entries.xml to it.


=== Zope3/src/zope/fssync/fsmerger.py 1.7 => 1.8 ===
--- Zope3/src/zope/fssync/fsmerger.py:1.7	Tue Jun  3 14:24:35 2003
+++ Zope3/src/zope/fssync/fsmerger.py	Tue Jun  3 16:01:37 2003
@@ -22,6 +22,8 @@
 from os.path import exists, isfile, isdir, split, join
 from os.path import realpath, normcase, normpath
 
+from zope.xmlpickle import dumps
+
 from zope.fssync.merger import Merger
 from zope.fssync import fsutil
 
@@ -95,10 +97,11 @@
                         self.reportdir("?", localdir)
                 else:
                     if not exists(localdir):
-                        fsutil.ensuredir(localdir)
+                        self.make_dir(localdir)
                         lentry.update(rentry)
                         self.reportdir("N", localdir)
                     else:
+                        self.make_dir(localdir)
                         self.reportdir("*", localdir)
                 return
 
@@ -147,7 +150,7 @@
                 self.reportdir("R", localdir)
                 return # There's no point in recursing down!
             if rentry or rentrynames:
-                fsutil.ensuredir(localdir)
+                self.make_dir(localdir)
                 lentry.update(rentry)
                 self.reportdir("N", localdir)
             lnames = {}
@@ -176,7 +179,33 @@
             name = names[ncname]
             self.merge(join(localdir, name), join(remotedir, name))
 
+    def make_dir(self, localdir):
+        """Helper to create a local directory.
+
+        This also creates the @@Zope subdirectory and places an empty
+        Entries.xml file in it.
+        """
+        fsutil.ensuredir(localdir)
+        localzopedir = join(localdir, "@@Zope")
+        fsutil.ensuredir(localzopedir)
+        efile = join(localzopedir, "Entries.xml")
+        if not os.path.exists(efile):
+            data = dumps({})
+            f = open(efile, "w")
+            try:
+                f.write(data)
+            finally:
+                f.close()
+
     def clear_dir(self, localdir):
+        """Helper to get rid of a local directory.
+
+        This zaps the directory's @@Zope subdirectory, but not other
+        files/directories that might still exist.
+
+        It doesn't deal with extras and annotations for the directory
+        itself, though.
+        """
         lentry = self.metadata.getentry(localdir)
         lentry.clear()
         localzopedir = join(localdir, "@@Zope")