archive: use util.opener when archiving files.
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Wed, 11 Jul 2007 17:40:41 -0300
changeset 4830 74f36b1027f4
parent 4829 0403b80352c9
child 4831 6f08bc1bd00b
archive: use util.opener when archiving files. This simplifies the code a bit and makes it easier to support symlinks.
mercurial/archival.py
--- a/mercurial/archival.py	Wed Jul 11 17:40:41 2007 -0300
+++ b/mercurial/archival.py	Wed Jul 11 17:40:41 2007 -0300
@@ -149,19 +149,14 @@
         if prefix:
             raise util.Abort(_('cannot give prefix when archiving to files'))
         self.basedir = name
-        self.dirs = {}
-        self.oflags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY |
-                       getattr(os, 'O_BINARY', 0) |
-                       getattr(os, 'O_NOFOLLOW', 0))
+        self.opener = util.opener(self.basedir)
 
     def addfile(self, name, mode, data):
+        f = self.opener(name, "w", atomictemp=True)
+        f.write(data)
+        f.rename()
         destfile = os.path.join(self.basedir, name)
-        destdir = os.path.dirname(destfile)
-        if destdir not in self.dirs:
-            if not os.path.isdir(destdir):
-                os.makedirs(destdir)
-            self.dirs[destdir] = 1
-        os.fdopen(os.open(destfile, self.oflags, mode), 'wb').write(data)
+        os.chmod(destfile, mode)
 
     def done(self):
         pass