Mercurial > hg
comparison hgext/largefiles/basestore.py @ 16154:9b072a5f8f92 stable
largefiles: respect store.createmode in basestore.get
This replaces another use of tempfile with atomictempfile. The problem
with tempfile is that it creates files with 600 permissions instead of
respecting repo.store.createmode.
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Thu, 23 Feb 2012 13:37:10 +0100 |
parents | f9efb325ea32 |
children | d87d9d8a8e03 |
comparison
equal
deleted
inserted
replaced
16153:05197f9fd1f3 | 16154:9b072a5f8f92 |
---|---|
6 # This software may be used and distributed according to the terms of the | 6 # This software may be used and distributed according to the terms of the |
7 # GNU General Public License version 2 or any later version. | 7 # GNU General Public License version 2 or any later version. |
8 | 8 |
9 '''base class for store implementations and store-related utility code''' | 9 '''base class for store implementations and store-related utility code''' |
10 | 10 |
11 import os | |
12 import tempfile | |
13 import binascii | 11 import binascii |
14 import re | 12 import re |
15 | 13 |
16 from mercurial import util, node, hg | 14 from mercurial import util, node, hg |
17 from mercurial.i18n import _ | 15 from mercurial.i18n import _ |
73 total=len(files)) | 71 total=len(files)) |
74 at += 1 | 72 at += 1 |
75 ui.note(_('getting %s:%s\n') % (filename, hash)) | 73 ui.note(_('getting %s:%s\n') % (filename, hash)) |
76 | 74 |
77 storefilename = lfutil.storepath(self.repo, hash) | 75 storefilename = lfutil.storepath(self.repo, hash) |
78 storedir = os.path.dirname(storefilename) | 76 tmpfile = util.atomictempfile(storefilename, |
79 | 77 createmode=self.repo.store.createmode) |
80 # No need to pass mode='wb' to fdopen(), since mkstemp() already | |
81 # opened the file in binary mode. | |
82 (tmpfd, tmpfilename) = tempfile.mkstemp( | |
83 dir=storedir, prefix=os.path.basename(filename)) | |
84 tmpfile = os.fdopen(tmpfd, 'w') | |
85 | 78 |
86 try: | 79 try: |
87 hhash = binascii.hexlify(self._getfile(tmpfile, filename, hash)) | 80 hhash = binascii.hexlify(self._getfile(tmpfile, filename, hash)) |
88 except StoreError, err: | 81 except StoreError, err: |
89 ui.warn(err.longmessage()) | 82 ui.warn(err.longmessage()) |
91 | 84 |
92 if hhash != hash: | 85 if hhash != hash: |
93 if hhash != "": | 86 if hhash != "": |
94 ui.warn(_('%s: data corruption (expected %s, got %s)\n') | 87 ui.warn(_('%s: data corruption (expected %s, got %s)\n') |
95 % (filename, hash, hhash)) | 88 % (filename, hash, hhash)) |
96 tmpfile.close() # no-op if it's already closed | 89 tmpfile.discard() # no-op if it's already closed |
97 os.remove(tmpfilename) | |
98 missing.append(filename) | 90 missing.append(filename) |
99 continue | 91 continue |
100 | 92 |
101 if os.path.exists(storefilename): # Windows | 93 tmpfile.close() |
102 os.remove(storefilename) | |
103 os.rename(tmpfilename, storefilename) | |
104 lfutil.linktousercache(self.repo, hash) | 94 lfutil.linktousercache(self.repo, hash) |
105 success.append((filename, hhash)) | 95 success.append((filename, hhash)) |
106 | 96 |
107 ui.progress(_('getting largefiles'), None) | 97 ui.progress(_('getting largefiles'), None) |
108 return (success, missing) | 98 return (success, missing) |