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