Always remove appendopener tmp files (fixes issue235).
authorThomas Arendsen Hein <thomas@intevation.de>
Tue, 09 May 2006 17:03:00 +0200
changeset 2232 ef3c039e7ab8
parent 2231 9a2f4b2e7cf1
child 2233 3840cefa5222
Always remove appendopener tmp files (fixes issue235). test-hup triggered this bug by killing "hg serve --stdio".
mercurial/appendfile.py
mercurial/localrepo.py
--- a/mercurial/appendfile.py	Tue May 09 13:26:16 2006 +0200
+++ b/mercurial/appendfile.py	Tue May 09 17:03:00 2006 +0200
@@ -134,10 +134,16 @@
             s = fp.read()
             fp.close()
             os.unlink(tmpname)
+            del self.tmpnames[name]
             fp = self.realopener(name, 'a')
             fp.write(s)
             fp.close()
 
+    def cleanup(self):
+        '''delete temp files (this discards unwritten data!)'''
+        for tmpname in self.tmpnames.values():
+            os.unlink(tmpname)
+
 # files for changelog and manifest are in different appendopeners, so
 # not mixed up together.
 
--- a/mercurial/localrepo.py	Tue May 09 13:26:16 2006 +0200
+++ b/mercurial/localrepo.py	Tue May 09 17:03:00 2006 +0200
@@ -1477,46 +1477,57 @@
 
         # write changelog and manifest data to temp files so
         # concurrent readers will not see inconsistent view
-        cl = appendfile.appendchangelog(self.opener, self.changelog.version)
+        cl = None
+        try:
+            cl = appendfile.appendchangelog(self.opener, self.changelog.version)
 
-        oldheads = len(cl.heads())
+            oldheads = len(cl.heads())
 
-        # pull off the changeset group
-        self.ui.status(_("adding changesets\n"))
-        co = cl.tip()
-        chunkiter = changegroup.chunkiter(source)
-        cn = cl.addgroup(chunkiter, csmap, tr, 1) # unique
-        cnr, cor = map(cl.rev, (cn, co))
-        if cn == nullid:
-            cnr = cor
-        changesets = cnr - cor
+            # pull off the changeset group
+            self.ui.status(_("adding changesets\n"))
+            co = cl.tip()
+            chunkiter = changegroup.chunkiter(source)
+            cn = cl.addgroup(chunkiter, csmap, tr, 1) # unique
+            cnr, cor = map(cl.rev, (cn, co))
+            if cn == nullid:
+                cnr = cor
+            changesets = cnr - cor
 
-        mf = appendfile.appendmanifest(self.opener, self.manifest.version)
+            mf = None
+            try:
+                mf = appendfile.appendmanifest(self.opener,
+                                               self.manifest.version)
 
-        # pull off the manifest group
-        self.ui.status(_("adding manifests\n"))
-        mm = mf.tip()
-        chunkiter = changegroup.chunkiter(source)
-        mo = mf.addgroup(chunkiter, revmap, tr)
+                # pull off the manifest group
+                self.ui.status(_("adding manifests\n"))
+                mm = mf.tip()
+                chunkiter = changegroup.chunkiter(source)
+                mo = mf.addgroup(chunkiter, revmap, tr)
 
-        # process the files
-        self.ui.status(_("adding file changes\n"))
-        while 1:
-            f = changegroup.getchunk(source)
-            if not f:
-                break
-            self.ui.debug(_("adding %s revisions\n") % f)
-            fl = self.file(f)
-            o = fl.count()
-            chunkiter = changegroup.chunkiter(source)
-            n = fl.addgroup(chunkiter, revmap, tr)
-            revisions += fl.count() - o
-            files += 1
+                # process the files
+                self.ui.status(_("adding file changes\n"))
+                while 1:
+                    f = changegroup.getchunk(source)
+                    if not f:
+                        break
+                    self.ui.debug(_("adding %s revisions\n") % f)
+                    fl = self.file(f)
+                    o = fl.count()
+                    chunkiter = changegroup.chunkiter(source)
+                    n = fl.addgroup(chunkiter, revmap, tr)
+                    revisions += fl.count() - o
+                    files += 1
 
-        # write order here is important so concurrent readers will see
-        # consistent view of repo
-        mf.writedata()
-        cl.writedata()
+                # write order here is important so concurrent readers will see
+                # consistent view of repo
+                mf.writedata()
+            finally:
+                if mf:
+                    mf.cleanup()
+            cl.writedata()
+        finally:
+            if cl:
+                cl.cleanup()
 
         # make changelog and manifest see real files again
         self.changelog = changelog.changelog(self.opener, self.changelog.version)