[PATCH 2 of 3 STABLE] largefiles: respect store.createmode in basestore.get
Martin Geisler
mg at aragost.com
Thu Feb 23 13:41:29 UTC 2012
# HG changeset patch
# User Martin Geisler <mg at aragost.com>
# Date 1330000630 -3600
# Branch stable
# Node ID 9b072a5f8f9284930a0441e0399e7cf2cf60e502
# Parent 05197f9fd1f3af0a978cee924d3223867e0ade1f
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.
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 @@
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))
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 @@
$ 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
More information about the Mercurial-devel
mailing list