diff hgext/largefiles/lfutil.py @ 15391:a5a6a9b7f3b9 stable

largefiles: replace tempfile.NamedTemporaryFile with tempfile.mkstemp This is consistent with the rest of Mercurial's code, mirroring the try-finally-unlink structure elsewhere. Furthermore, it fixes the case where largefiles throws an IOError on Windows when the temporary file is opened a second time by copytocacheabsolute. This patch creates the temporary file in the repo's largefiles store rather than /tmp, which might be a different filesystem.
author Hao Lian <hao@fogcreek.com>
date Thu, 20 Oct 2011 17:24:59 -0400
parents f26ed4ea46d8
children d7bfbc92a1c0
line wrap: on
line diff
--- a/hgext/largefiles/lfutil.py	Mon Oct 31 14:22:11 2011 -0500
+++ b/hgext/largefiles/lfutil.py	Thu Oct 20 17:24:59 2011 -0400
@@ -13,6 +13,7 @@
 import platform
 import shutil
 import stat
+import tempfile
 
 from mercurial import dirstate, httpconnection, match as match_, util, scmutil
 from mercurial.i18n import _
@@ -438,6 +439,13 @@
     return ('largefiles' in repo.requirements and
             util.any(shortname + '/' in f[0] for f in repo.store.datafiles()))
 
+def mkstemp(repo, prefix):
+    '''Returns a file descriptor and a filename corresponding to a temporary
+    file in the repo's largefiles store.'''
+    path = repo.join(longname)
+    util.makedirs(repo.join(path))
+    return tempfile.mkstemp(prefix=prefix, dir=path)
+
 class storeprotonotcapable(Exception):
     def __init__(self, storetypes):
         self.storetypes = storetypes