Commits

Martin Geisler committed 9b072a5

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.

  • Participants
  • Parent commits 05197f9
  • Branches stable

Comments (0)

Files changed (2)

hgext/largefiles/basestore.py

 
 '''base class for store implementations and store-related utility code'''
 
-import os
-import tempfile
 import binascii
 import re
 
             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))
                 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))
 

tests/test-largefiles-cache.t

   $ 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