Mercurial > hg
changeset 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 | 05197f9fd1f3 |
children | 1b2b42e866be |
files | hgext/largefiles/basestore.py tests/test-largefiles-cache.t |
diffstat | 2 files changed, 13 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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))
--- a/tests/test-largefiles-cache.t Thu Feb 23 13:22:55 2012 +0100 +++ b/tests/test-largefiles-cache.t Thu Feb 23 13:37:10 2012 +0100 @@ -94,3 +94,12 @@ $ hg commit -m change $ ../ls-l.py .hg/largefiles/e151b474069de4ca6898f67ce2f2a7263adf8fea 640 + +Test permission of with files in .hg/largefiles created by update: + + $ cd ../mirror + $ rm -r "$USERCACHE" .hg/largefiles # avoid links + $ chmod 750 .hg/store + $ hg pull ../src --update -q + $ ../ls-l.py .hg/largefiles/e151b474069de4ca6898f67ce2f2a7263adf8fea + 640