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