diff --git a/hgext/largefiles/basestore.py b/hgext/largefiles/basestore.py --- a/hgext/largefiles/basestore.py +++ b/hgext/largefiles/basestore.py @@ -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 @@ class basestore(object): 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 @@ class basestore(object): 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)) diff --git a/tests/test-largefiles-cache.t b/tests/test-largefiles-cache.t --- a/tests/test-largefiles-cache.t +++ b/tests/test-largefiles-cache.t @@ -94,3 +94,12 @@ from file in working copy: $ 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