##// END OF EJS Templates
largefiles: replace tempfile.NamedTemporaryFile with tempfile.mkstemp...
Hao Lian -
r15391:a5a6a9b7 stable
parent child Browse files
Show More
@@ -13,6 +13,7 b' import errno'
13 13 import platform
14 14 import shutil
15 15 import stat
16 import tempfile
16 17
17 18 from mercurial import dirstate, httpconnection, match as match_, util, scmutil
18 19 from mercurial.i18n import _
@@ -438,6 +439,13 b' def islfilesrepo(repo):'
438 439 return ('largefiles' in repo.requirements and
439 440 util.any(shortname + '/' in f[0] for f in repo.store.datafiles()))
440 441
442 def mkstemp(repo, prefix):
443 '''Returns a file descriptor and a filename corresponding to a temporary
444 file in the repo's largefiles store.'''
445 path = repo.join(longname)
446 util.makedirs(repo.join(path))
447 return tempfile.mkstemp(prefix=prefix, dir=path)
448
441 449 class storeprotonotcapable(Exception):
442 450 def __init__(self, storetypes):
443 451 self.storetypes = storetypes
@@ -4,7 +4,6 b''
4 4 # GNU General Public License version 2 or any later version.
5 5
6 6 import os
7 import tempfile
8 7 import urllib2
9 8
10 9 from mercurial import error, httprepo, util, wireproto
@@ -19,23 +18,25 b" LARGEFILES_REQUIRED_MSG = ('\\nThis repos"
19 18 def putlfile(repo, proto, sha):
20 19 '''Put a largefile into a repository's local store and into the
21 20 user cache.'''
22 f = None
23 21 proto.redirect()
22
23 fd, tmpname = lfutil.mkstemp(repo, prefix='hg-putlfile')
24 tmpfp = os.fdopen(fd, 'wb+')
24 25 try:
25 26 try:
26 f = tempfile.NamedTemporaryFile(mode='wb+', prefix='hg-putlfile-')
27 proto.getfile(f)
28 f.seek(0)
29 if sha != lfutil.hexsha1(f):
27 proto.getfile(tmpfp)
28 tmpfp.seek(0)
29 if sha != lfutil.hexsha1(tmpfp):
30 30 return wireproto.pushres(1)
31 lfutil.copytostoreabsolute(repo, f.name, sha)
32 except IOError:
33 repo.ui.warn(
34 _('error: could not put received data into largefile store'))
31 tmpfp.close()
32 lfutil.copytostoreabsolute(repo, tmpname, sha)
33 except IOError, e:
34 repo.ui.warn(_('largefiles: failed to put %s (%s) into store: %s') %
35 (sha, tmpname, e.strerror))
35 36 return wireproto.pushres(1)
36 37 finally:
37 if f:
38 f.close()
38 tmpfp.close()
39 os.unlink(tmpname)
39 40
40 41 return wireproto.pushres(0)
41 42
General Comments 0
You need to be logged in to leave comments. Login now