hgext/largefiles/basestore.py
branchstable
changeset 16154 9b072a5f8f92
parent 15943 f9efb325ea32
child 16247 d87d9d8a8e03
--- a/hgext/largefiles/basestore.py	Thu Feb 23 13:22:55 2012 +0100
+++ b/hgext/largefiles/basestore.py	Thu Feb 23 13:37:10 2012 +0100
@@ -8,8 +8,6 @@
 
 '''base class for store implementations and store-related utility code'''
 
-import os
-import tempfile
 import binascii
 import re
 
@@ -75,13 +73,8 @@
             ui.note(_('getting %s:%s\n') % (filename, hash))
 
             storefilename = lfutil.storepath(self.repo, hash)
-            storedir = os.path.dirname(storefilename)
-
-            # No need to pass mode='wb' to fdopen(), since mkstemp() already
-            # opened the file in binary mode.
-            (tmpfd, tmpfilename) = tempfile.mkstemp(
-                dir=storedir, prefix=os.path.basename(filename))
-            tmpfile = os.fdopen(tmpfd, 'w')
+            tmpfile = util.atomictempfile(storefilename,
+                                          createmode=self.repo.store.createmode)
 
             try:
                 hhash = binascii.hexlify(self._getfile(tmpfile, filename, hash))
@@ -93,14 +86,11 @@
                 if hhash != "":
                     ui.warn(_('%s: data corruption (expected %s, got %s)\n')
                             % (filename, hash, hhash))
-                tmpfile.close() # no-op if it's already closed
-                os.remove(tmpfilename)
+                tmpfile.discard() # no-op if it's already closed
                 missing.append(filename)
                 continue
 
-            if os.path.exists(storefilename): # Windows
-                os.remove(storefilename)
-            os.rename(tmpfilename, storefilename)
+            tmpfile.close()
             lfutil.linktousercache(self.repo, hash)
             success.append((filename, hhash))