Debian Codegraph @

tests/test-inherit-mode.t

raw
1 #require unix-permissions
2
3 test that new files created in .hg inherit the permissions from .hg/store
4
5 $ mkdir dir
6
7 just in case somebody has a strange $TMPDIR
8
9 $ chmod g-s dir
10 $ cd dir
11
12 $ cat >printmodes.py <<EOF
13 > import os
14 > import sys
15 >
16 > allnames = []
17 > isdir = {}
18 > for root, dirs, files in os.walk(sys.argv[1]):
19 > for d in dirs:
20 > name = os.path.join(root, d)
21 > isdir[name] = 1
22 > allnames.append(name)
23 > for f in files:
24 > name = os.path.join(root, f)
25 > allnames.append(name)
26 > allnames.sort()
27 > for name in allnames:
28 > suffix = name in isdir and '/' or ''
29 > print('%05o %s%s' % (os.lstat(name).st_mode & 0o7777, name, suffix))
30 > EOF
31
32 $ cat >mode.py <<EOF
33 > import os
34 > import sys
35 > print('%05o' % os.lstat(sys.argv[1]).st_mode)
36 > EOF
37
38 $ umask 077
39
40 $ hg init repo
41 $ cd repo
42
43 $ chmod 0770 .hg/store .hg/cache .hg/wcache
44
45 before commit
46 store can be written by the group, other files cannot
47 store is setgid
48
49 $ "$PYTHON" ../printmodes.py .
50 00700 ./.hg/
51 00600 ./.hg/00changelog.i
52 00770 ./.hg/cache/
53 00600 ./.hg/requires
54 00770 ./.hg/store/
55 00600 ./.hg/store/requires
56 00770 ./.hg/wcache/
57
58 $ mkdir dir
59 $ touch foo dir/bar
60 $ hg ci -qAm 'add files'
61
62 after commit
63 working dir files can only be written by the owner
64 files created in .hg can be written by the group
65 (in particular, store/**, dirstate, branch cache file, undo files)
66 new directories are setgid
67
68 $ "$PYTHON" ../printmodes.py .
69 00700 ./.hg/
70 00600 ./.hg/00changelog.i
71 00660 ./.hg/branch
72 00770 ./.hg/cache/
73 00660 ./.hg/cache/branch2-served
74 00660 ./.hg/cache/rbc-names-v2
75 00660 ./.hg/cache/rbc-revs-v2
76 00660 ./.hg/dirstate
77 00660 ./.hg/fsmonitor.state (fsmonitor !)
78 00660 ./.hg/last-message.txt
79 00600 ./.hg/requires
80 00770 ./.hg/store/
81 00660 ./.hg/store/00changelog-150e1cfc.nd (rust !)
82 00660 ./.hg/store/00changelog.d
83 00660 ./.hg/store/00changelog.i
84 00660 ./.hg/store/00changelog.n (rust !)
85 00660 ./.hg/store/00manifest.i
86 00770 ./.hg/store/data/
87 00770 ./.hg/store/data/dir/
88 00660 ./.hg/store/data/dir/bar.i
89 00660 ./.hg/store/data/foo.i
90 00660 ./.hg/store/fncache
91 00660 ./.hg/store/phaseroots
92 00600 ./.hg/store/requires
93 00660 ./.hg/store/undo
94 00660 ./.hg/store/undo.backupfiles
95 00660 ./.hg/undo.backup.branch.bck
96 00660 ./.hg/undo.desc
97 00770 ./.hg/wcache/
98 00711 ./.hg/wcache/checkisexec
99 007.. ./.hg/wcache/checklink (re)
100 00600 ./.hg/wcache/checklink-target
101 00660 ./.hg/wcache/manifestfulltextcache
102 00700 ./dir/
103 00600 ./dir/bar
104 00600 ./foo
105
106 $ umask 007
107 $ hg init ../push
108
109 before push
110 group can write everything
111
112 $ "$PYTHON" ../printmodes.py ../push
113 00770 ../push/.hg/
114 00660 ../push/.hg/00changelog.i
115 00770 ../push/.hg/cache/
116 00660 ../push/.hg/requires
117 00770 ../push/.hg/store/
118 00660 ../push/.hg/store/requires
119 00770 ../push/.hg/wcache/
120
121 $ umask 077
122 $ hg -q push ../push
123
124 after push
125 group can still write everything
126
127 $ "$PYTHON" ../printmodes.py ../push
128 00770 ../push/.hg/
129 00660 ../push/.hg/00changelog.i
130 00660 ../push/.hg/branch
131 00770 ../push/.hg/cache/
132 00660 ../push/.hg/cache/branch2-base
133 00660 ../push/.hg/cache/rbc-names-v2
134 00660 ../push/.hg/cache/rbc-revs-v2
135 00660 ../push/.hg/requires
136 00770 ../push/.hg/store/
137 00660 ../push/.hg/store/00changelog-b870a51b.nd (rust !)
138 00660 ../push/.hg/store/00changelog.d
139 00660 ../push/.hg/store/00changelog.i
140 00660 ../push/.hg/store/00changelog.n (rust !)
141 00660 ../push/.hg/store/00manifest.i
142 00770 ../push/.hg/store/data/
143 00770 ../push/.hg/store/data/dir/
144 00660 ../push/.hg/store/data/dir/bar.i
145 00660 ../push/.hg/store/data/foo.i
146 00660 ../push/.hg/store/fncache
147 00660 ../push/.hg/store/requires
148 00660 ../push/.hg/store/undo
149 00660 ../push/.hg/store/undo.backupfiles
150 00660 ../push/.hg/undo.backup.branch.bck
151 00660 ../push/.hg/undo.desc
152 00770 ../push/.hg/wcache/
153
154
155 Test that we don't lose the setgid bit when we call chmod.
156 Not all systems support setgid directories (e.g. HFS+), so
157 just check that directories have the same mode.
158
159 $ cd ..
160 $ hg init setgid
161 $ cd setgid
162 $ chmod g+rwx .hg/store
163 $ chmod g+s .hg/store 2> /dev/null || true
164 $ mkdir dir
165 $ touch dir/file
166 $ hg ci -qAm 'add dir/file'
167 $ storemode=`"$PYTHON" ../mode.py .hg/store`
168 $ dirmode=`"$PYTHON" ../mode.py .hg/store/data/dir`
169 $ if [ "$storemode" != "$dirmode" ]; then
170 > echo "$storemode != $dirmode"
171 > fi
172 $ cd ..
173
174 $ cd .. # g-s dir