/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_permissions.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
 
84
84
        t = self.make_branch_and_tree('.')
85
85
        b = t.branch
86
 
        with open('a', 'wb') as f: f.write('foo\n')
 
86
        with open('a', 'wb') as f:
 
87
            f.write(b'foo\n')
87
88
        # ensure check_mode_r works with capital-letter file-ids like TREE_ROOT
88
 
        t.add('a', 'CAPS-ID')
 
89
        t.add('a', b'CAPS-ID')
89
90
        t.commit('foo')
90
91
 
91
92
        chmod_r('.bzr', 0o644, 0o755)
104
105
        self.assertEqualMode(0o644, b.controldir._get_file_mode())
105
106
 
106
107
        # Modifying a file shouldn't break the permissions
107
 
        with open('a', 'wb') as f: f.write('foo2\n')
 
108
        with open('a', 'wb') as f:
 
109
            f.write(b'foo2\n')
108
110
        t.commit('foo2')
109
111
        # The mode should be maintained after commit
110
112
        check_mode_r(self, '.bzr', 0o644, 0o755)
111
113
 
112
114
        # Adding a new file should maintain the permissions
113
 
        with open('b', 'wb') as f: f.write('new b\n')
 
115
        with open('b', 'wb') as f:
 
116
            f.write(b'new b\n')
114
117
        t.add('b')
115
118
        t.commit('new b')
116
119
        check_mode_r(self, '.bzr', 0o644, 0o755)
125
128
        self.assertEqualMode(0o775, b.controldir._get_dir_mode())
126
129
        self.assertEqualMode(0o664, b.controldir._get_file_mode())
127
130
 
128
 
        with open('a', 'wb') as f: f.write('foo3\n')
 
131
        with open('a', 'wb') as f:
 
132
            f.write(b'foo3\n')
129
133
        t.commit('foo3')
130
134
        check_mode_r(self, '.bzr', 0o664, 0o775)
131
135
 
132
 
        with open('c', 'wb') as f: f.write('new c\n')
 
136
        with open('c', 'wb') as f:
 
137
            f.write(b'new c\n')
133
138
        t.add('c')
134
139
        t.commit('new c')
135
140
        check_mode_r(self, '.bzr', 0o664, 0o775)
157
162
        self.assertEqualMode(0o2775, b.controldir._get_dir_mode())
158
163
        self.assertEqualMode(0o664, b.controldir._get_file_mode())
159
164
 
160
 
        with open('a', 'wb') as f: f.write('foo4\n')
 
165
        with open('a', 'wb') as f:
 
166
            f.write(b'foo4\n')
161
167
        t.commit('foo4')
162
168
        check_mode_r(self, '.bzr', 0o664, 0o2775)
163
169
 
164
 
        with open('d', 'wb') as f: f.write('new d\n')
 
170
        with open('d', 'wb') as f:
 
171
            f.write(b'new d\n')
165
172
        t.add('d')
166
173
        t.commit('new d')
167
174
        check_mode_r(self, '.bzr', 0o664, 0o2775)
182
189
        os.mkdir('local')
183
190
        t_local = self.make_branch_and_tree('local')
184
191
        b_local = t_local.branch
185
 
        with open('local/a', 'wb') as f: f.write('foo\n')
 
192
        with open('local/a', 'wb') as f:
 
193
            f.write(b'foo\n')
186
194
        t_local.add('a')
187
195
        t_local.commit('foo')
188
196
 
212
220
        self.assertEqualMode(0o755, b_sftp.controldir._get_dir_mode())
213
221
        self.assertEqualMode(0o644, b_sftp.controldir._get_file_mode())
214
222
 
215
 
        with open('local/a', 'wb') as f: f.write('foo2\n')
 
223
        with open('local/a', 'wb') as f:
 
224
            f.write(b'foo2\n')
216
225
        t_local.commit('foo2')
217
226
        b_sftp.pull(b_local)
218
227
        # The mode should be maintained after commit
219
228
        check_mode_r(self, 'sftp/.bzr', 0o644, 0o755)
220
229
 
221
 
        with open('local/b', 'wb') as f: f.write('new b\n')
 
230
        with open('local/b', 'wb') as f:
 
231
            f.write(b'new b\n')
222
232
        t_local.add('b')
223
233
        t_local.commit('new b')
224
234
        b_sftp.pull(b_local)
235
245
        self.assertEqualMode(0o775, b_sftp.controldir._get_dir_mode())
236
246
        self.assertEqualMode(0o664, b_sftp.controldir._get_file_mode())
237
247
 
238
 
        with open('local/a', 'wb') as f: f.write('foo3\n')
 
248
        with open('local/a', 'wb') as f:
 
249
            f.write(b'foo3\n')
239
250
        t_local.commit('foo3')
240
251
        b_sftp.pull(b_local)
241
252
        check_mode_r(self, 'sftp/.bzr', 0o664, 0o775)
242
253
 
243
 
        with open('local/c', 'wb') as f: f.write('new c\n')
 
254
        with open('local/c', 'wb') as f:
 
255
            f.write(b'new c\n')
244
256
        t_local.add('c')
245
257
        t_local.commit('new c')
246
258
        b_sftp.pull(b_local)
256
268
        try:
257
269
            t = self.get_transport()
258
270
            # Direct access should be masked by umask
259
 
            t._sftp_open_exclusive('a', mode=0o666).write('foo\n')
260
 
            self.assertTransportMode(t, 'a', 0o666 &~umask)
 
271
            with t._sftp_open_exclusive('a', mode=0o666) as f:
 
272
                f.write(b'foo\n')
 
273
            self.assertTransportMode(t, 'a', 0o666 & ~umask)
261
274
 
262
275
            # but Transport overrides umask
263
 
            t.put_bytes('b', 'txt', mode=0o666)
 
276
            t.put_bytes('b', b'txt', mode=0o666)
264
277
            self.assertTransportMode(t, 'b', 0o666)
265
278
 
266
279
            t._get_sftp().mkdir('c', mode=0o777)
267
 
            self.assertTransportMode(t, 'c', 0o777 &~umask)
 
280
            self.assertTransportMode(t, 'c', 0o777 & ~umask)
268
281
 
269
282
            t.mkdir('d', mode=0o777)
270
283
            self.assertTransportMode(t, 'd', 0o777)