[PATCH 1 of 3 STABLE] largefiles: use repo.store.createmode for new files in .hg/largefiles

Martin Geisler mg at aragost.com
Thu Feb 23 07:41:28 CST 2012


# HG changeset patch
# User Martin Geisler <mg at aragost.com>
# Date 1329999775 -3600
# Branch stable
# Node ID 05197f9fd1f3af0a978cee924d3223867e0ade1f
# Parent  616c2e278f18984dc48b80bc56b55da626130709
largefiles: use repo.store.createmode for new files in .hg/largefiles

Before, the mode was copied from the file in the working copy. This is
inconsistent with how Mercurial normally creates files inside the .hg
folder. This can lead to a situation where you can read the files
under .hg/store but not under .hg/largefiles and so a clone will fail
if it needs to access a largefile.

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -237,11 +237,11 @@
     if inusercache(repo.ui, hash):
         link(usercachepath(repo.ui, hash), storepath(repo, hash))
     else:
-        dst = util.atomictempfile(storepath(repo, hash))
+        dst = util.atomictempfile(storepath(repo, hash),
+                                  createmode=repo.store.createmode)
         for chunk in util.filechunkiter(open(file, 'rb')):
             dst.write(chunk)
         dst.close()
-        util.copymode(file, storepath(repo, hash))
         linktousercache(repo, hash)
 
 def linktousercache(repo, hash):
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
@@ -1,3 +1,5 @@
+  $ "$TESTDIR/hghave" unix-permissions || exit 80
+
 Create user cache directory
 
   $ USERCACHE=`pwd`/cache; export USERCACHE
@@ -70,3 +72,25 @@
   0 largefiles updated, 0 removed
   $ hg status
   ! large
+
+Portable way to print file permissions:
+
+  $ cd ..
+  $ cat > ls-l.py <<EOF
+  > #!/usr/bin/env python
+  > import sys, os
+  > path = sys.argv[1]
+  > print '%03o' % (os.lstat(path).st_mode & 0777)
+  > EOF
+  $ chmod +x ls-l.py
+
+Test that files in .hg/largefiles inherit mode from .hg/store, not
+from file in working copy:
+
+  $ cd src
+  $ chmod 750 .hg/store
+  $ chmod 660 large
+  $ echo change >> large
+  $ hg commit -m change
+  $ ../ls-l.py .hg/largefiles/e151b474069de4ca6898f67ce2f2a7263adf8fea
+  640


More information about the Mercurial-devel mailing list