|
1 #require execbit unix-permissions |
|
2 |
|
3 Checking that experimental.atomic-file works. |
|
4 |
|
5 $ cat > $TESTTMP/show_mode.py <<EOF |
|
6 > from __future__ import print_function |
|
7 > import sys |
|
8 > import os |
|
9 > from stat import ST_MODE |
|
10 > |
|
11 > for file_path in sys.argv[1:]: |
|
12 > file_stat = os.stat(file_path) |
|
13 > octal_mode = oct(file_stat[ST_MODE] & 0o777) |
|
14 > print("%s:%s" % (file_path, octal_mode)) |
|
15 > |
|
16 > EOF |
|
17 |
|
18 $ hg init repo |
|
19 $ cd repo |
|
20 |
|
21 $ cat > .hg/showwrites.py <<EOF |
|
22 > def uisetup(ui): |
|
23 > from mercurial import vfs |
|
24 > class newvfs(vfs.vfs): |
|
25 > def __call__(self, *args, **kwargs): |
|
26 > print('vfs open', args, sorted(list(kwargs.items()))) |
|
27 > return super(newvfs, self).__call__(*args, **kwargs) |
|
28 > vfs.vfs = newvfs |
|
29 > EOF |
|
30 |
|
31 $ for v in a1 a2 b1 b2 c ro; do echo $v > $v; done |
|
32 $ chmod +x b* |
|
33 $ hg commit -Aqm _ |
|
34 |
|
35 # We check that |
|
36 # - the changes are actually atomic |
|
37 # - that permissions are correct (all 4 cases of (executable before) * (executable after)) |
|
38 # - that renames work, though they should be atomic anyway |
|
39 # - that it works when source files are read-only (but directories are read-write still) |
|
40 |
|
41 $ for v in a1 a2 b1 b2 ro; do echo changed-$v > $v; done |
|
42 $ chmod -x *1; chmod +x *2 |
|
43 $ hg rename c d |
|
44 $ hg commit -qm _ |
|
45 |
|
46 Check behavior without update.atomic-file |
|
47 |
|
48 $ hg update -r 0 -q |
|
49 $ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb" |
|
50 ('vfs open', ('a1', 'wb'), [('atomictemp', False), ('backgroundclose', True)]) |
|
51 |
|
52 $ python $TESTTMP/show_mode.py * |
|
53 a1:0644 |
|
54 a2:0755 |
|
55 b1:0644 |
|
56 b2:0755 |
|
57 d:0644 |
|
58 ro:0644 |
|
59 |
|
60 Add a second revision for the ro file so we can test update when the file is |
|
61 present or not |
|
62 |
|
63 $ echo "ro" > ro |
|
64 |
|
65 $ hg commit -qm _ |
|
66 |
|
67 Check behavior without update.atomic-file first |
|
68 |
|
69 $ hg update -C -r 0 -q |
|
70 |
|
71 $ hg update -r 1 |
|
72 6 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
73 |
|
74 $ python $TESTTMP/show_mode.py * |
|
75 a1:0644 |
|
76 a2:0755 |
|
77 b1:0644 |
|
78 b2:0755 |
|
79 d:0644 |
|
80 ro:0644 |
|
81 |
|
82 Manually reset the mode of the read-only file |
|
83 |
|
84 $ chmod a-w ro |
|
85 |
|
86 $ python $TESTTMP/show_mode.py ro |
|
87 ro:0444 |
|
88 |
|
89 Now the file is present, try to update and check the permissions of the file |
|
90 |
|
91 $ hg up -r 2 |
|
92 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
93 |
|
94 $ python $TESTTMP/show_mode.py ro |
|
95 ro:0644 |
|
96 |
|
97 # The file which was read-only is now writable in the default behavior |
|
98 |
|
99 Check behavior with update.atomic-files |
|
100 |
|
101 |
|
102 $ cat >> .hg/hgrc <<EOF |
|
103 > [experimental] |
|
104 > update.atomic-file = true |
|
105 > EOF |
|
106 |
|
107 $ hg update -C -r 0 -q |
|
108 $ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb" |
|
109 ('vfs open', ('a1', 'wb'), [('atomictemp', True), ('backgroundclose', True)]) |
|
110 $ hg st -A --rev 1 |
|
111 C a1 |
|
112 C a2 |
|
113 C b1 |
|
114 C b2 |
|
115 C d |
|
116 C ro |
|
117 |
|
118 Check the file permission after update |
|
119 $ python $TESTTMP/show_mode.py * |
|
120 a1:0644 |
|
121 a2:0755 |
|
122 b1:0644 |
|
123 b2:0755 |
|
124 d:0644 |
|
125 ro:0644 |
|
126 |
|
127 Manually reset the mode of the read-only file |
|
128 |
|
129 $ chmod a-w ro |
|
130 |
|
131 $ python $TESTTMP/show_mode.py ro |
|
132 ro:0444 |
|
133 |
|
134 Now the file is present, try to update and check the permissions of the file |
|
135 |
|
136 $ hg update -r 2 --traceback |
|
137 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
138 |
|
139 $ python $TESTTMP/show_mode.py ro |
|
140 ro:0644 |
|
141 |
|
142 # The behavior is the same as without atomic update |