48
48
def chmod_r(base, file_mode, dir_mode):
49
49
"""Recursively chmod from a base directory"""
50
assert os.path.isdir(base)
51
50
os.chmod(base, dir_mode)
52
51
for root, dirs, files in os.walk(base):
67
66
:param dir_mode: The mode for all directories
68
67
:param include_base: If false, only check the subdirectories
70
assert os.path.isdir(base)
71
69
t = get_transport(".")
73
71
test.assertTransportMode(t, base, dir_mode)
107
105
self.assertEqualMode(0755, b.control_files._dir_mode)
108
106
self.assertEqualMode(0644, b.control_files._file_mode)
107
self.assertEqualMode(0755, b.bzrdir._get_dir_mode())
108
self.assertEqualMode(0644, b.bzrdir._get_file_mode())
110
110
# Modifying a file shouldn't break the permissions
111
111
open('a', 'wb').write('foo2\n')
127
127
self.assertEqualMode(0775, b.control_files._dir_mode)
128
128
self.assertEqualMode(0664, b.control_files._file_mode)
129
self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
130
self.assertEqualMode(0664, b.bzrdir._get_file_mode())
130
132
open('a', 'wb').write('foo3\n')
145
147
self.assertEqualMode(02775, b.control_files._dir_mode)
146
148
self.assertEqualMode(0664, b.control_files._file_mode)
149
self.assertEqualMode(02775, b.bzrdir._get_dir_mode())
150
self.assertEqualMode(0664, b.bzrdir._get_file_mode())
148
152
open('a', 'wb').write('foo4\n')
154
158
t.commit('new d')
155
159
check_mode_r(self, '.bzr', 0664, 02775)
157
def test_disable_set_mode(self):
158
# TODO: jam 20051215 Ultimately, this test should probably test that
159
# extra chmod calls aren't being made
161
transport = get_transport(self.get_url())
162
transport.put_bytes('my-lock', '')
163
lockable = LockableFiles(transport, 'my-lock', TransportLock)
164
self.assertNotEqual(None, lockable._dir_mode)
165
self.assertNotEqual(None, lockable._file_mode)
167
LockableFiles._set_dir_mode = False
168
transport = get_transport('.')
169
lockable = LockableFiles(transport, 'my-lock', TransportLock)
170
self.assertEqual(None, lockable._dir_mode)
171
self.assertNotEqual(None, lockable._file_mode)
173
LockableFiles._set_file_mode = False
174
transport = get_transport('.')
175
lockable = LockableFiles(transport, 'my-lock', TransportLock)
176
self.assertEqual(None, lockable._dir_mode)
177
self.assertEqual(None, lockable._file_mode)
179
LockableFiles._set_dir_mode = True
180
transport = get_transport('.')
181
lockable = LockableFiles(transport, 'my-lock', TransportLock)
182
self.assertNotEqual(None, lockable._dir_mode)
183
self.assertEqual(None, lockable._file_mode)
185
LockableFiles._set_file_mode = True
186
transport = get_transport('.')
187
lockable = LockableFiles(transport, 'my-lock', TransportLock)
188
self.assertNotEqual(None, lockable._dir_mode)
189
self.assertNotEqual(None, lockable._file_mode)
191
LockableFiles._set_dir_mode = True
192
LockableFiles._set_file_mode = True
195
162
class TestSftpPermissions(TestCaseWithSFTPServer):
219
186
b_local = t.branch
220
187
self.assertEqualMode(0755, b_local.control_files._dir_mode)
221
188
self.assertEqualMode(0644, b_local.control_files._file_mode)
189
self.assertEqualMode(0755, b_local.bzrdir._get_dir_mode())
190
self.assertEqualMode(0644, b_local.bzrdir._get_file_mode())
224
193
sftp_url = self.get_url('sftp')
232
201
b_sftp = Branch.open(sftp_url)
233
202
self.assertEqualMode(0755, b_sftp.control_files._dir_mode)
234
203
self.assertEqualMode(0644, b_sftp.control_files._file_mode)
204
self.assertEqualMode(0755, b_sftp.bzrdir._get_dir_mode())
205
self.assertEqualMode(0644, b_sftp.bzrdir._get_file_mode())
236
207
open('local/a', 'wb').write('foo2\n')
237
208
t_local.commit('foo2')
253
224
b_sftp = Branch.open(sftp_url)
254
225
self.assertEqualMode(0775, b_sftp.control_files._dir_mode)
255
226
self.assertEqualMode(0664, b_sftp.control_files._file_mode)
227
self.assertEqualMode(0775, b_sftp.bzrdir._get_dir_mode())
228
self.assertEqualMode(0664, b_sftp.bzrdir._get_file_mode())
257
230
open('local/a', 'wb').write('foo3\n')
258
231
t_local.commit('foo3')