~lifeless/bzr/index.range_map

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

  • Committer: Robert Collins
  • Date: 2008-06-19 01:17:19 UTC
  • mfrom: (3218.1.277 +trunk)
  • Revision ID: robertc@robertcollins.net-20080619011719-1c4g4uxzzhdls2wf
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
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):
53
52
        for d in dirs:
67
66
    :param dir_mode: The mode for all directories
68
67
    :param include_base: If false, only check the subdirectories
69
68
    """
70
 
    assert os.path.isdir(base)
71
69
    t = get_transport(".")
72
70
    if include_base:
73
71
        test.assertTransportMode(t, base, dir_mode)
106
104
        b = t.branch
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())
109
109
 
110
110
        # Modifying a file shouldn't break the permissions
111
111
        open('a', 'wb').write('foo2\n')
126
126
        b = t.branch
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())
129
131
 
130
132
        open('a', 'wb').write('foo3\n')
131
133
        t.commit('foo3')
144
146
        b = t.branch
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())
147
151
 
148
152
        open('a', 'wb').write('foo4\n')
149
153
        t.commit('foo4')
154
158
        t.commit('new d')
155
159
        check_mode_r(self, '.bzr', 0664, 02775)
156
160
 
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
160
 
        try:
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)
166
 
 
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)
172
 
 
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)
178
 
 
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)
184
 
 
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)
190
 
        finally:
191
 
            LockableFiles._set_dir_mode = True
192
 
            LockableFiles._set_file_mode = True
193
 
 
194
161
 
195
162
class TestSftpPermissions(TestCaseWithSFTPServer):
196
163
 
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())
222
191
 
223
192
        os.mkdir('sftp')
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())
235
206
 
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())
256
229
 
257
230
        open('local/a', 'wb').write('foo3\n')
258
231
        t_local.commit('foo3')