~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

  • Committer: Martin Pool
  • Date: 2006-01-12 06:37:23 UTC
  • mfrom: (1534.1.6 integration)
  • Revision ID: mbp@sourcefrog.net-20060112063723-4ec91b5ff30f0830
[merge] robertc-integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from bzrlib.branch import Branch
38
38
from bzrlib.tests import TestCaseInTempDir, TestSkipped
39
39
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
 
from bzrlib.tests.test_transport import check_mode
 
40
from bzrlib.transport import get_transport
41
41
 
42
42
 
43
43
def chmod_r(base, file_mode, dir_mode):
63
63
    :param include_base: If false, only check the subdirectories
64
64
    """
65
65
    assert os.path.isdir(base)
 
66
    t = get_transport(".")
66
67
    if include_base:
67
 
        check_mode(test, base, dir_mode)
 
68
        test.assertTransportMode(t, base, dir_mode)
68
69
    for root, dirs, files in os.walk(base):
69
70
        for d in dirs:
70
71
            p = os.path.join(root, d)
71
 
            check_mode(test, p, dir_mode)
 
72
            test.assertTransportMode(t, p, dir_mode)
72
73
        for f in files:
73
74
            p = os.path.join(root, f)
74
 
            check_mode(test, p, file_mode)
 
75
            test.assertTransportMode(t, p, file_mode)
75
76
 
76
77
 
77
78
def assertEqualMode(test, mode, mode_test):
227
228
        # We don't actually use it directly, we just want to
228
229
        # keep the connection open, since StubSFTPServer only
229
230
        # allows 1 connection
230
 
        self.delayed_setup()
231
231
        _transport = SFTPTransport(self._sftp_url)
232
232
 
233
233
        os.mkdir('local')
248
248
        assertEqualMode(self, 0644, b_local._file_mode)
249
249
 
250
250
        os.mkdir('sftp')
251
 
        # Why does self._sftp_url end with a slash????
252
 
        sftp_url = self._sftp_url + 'sftp'
 
251
        sftp_url = self.get_remote_url('sftp')
253
252
        b_sftp = Branch.initialize(sftp_url)
254
253
 
255
254
        b_sftp.pull(b_local)
302
301
 
303
302
        try:
304
303
            from bzrlib.transport.sftp import SFTPTransport
305
 
            self.delayed_setup()
306
304
            t = SFTPTransport(self._sftp_url)
307
305
            # Direct access should be masked by umask
308
306
            t._sftp_open_exclusive('a', mode=0666).write('foo\n')
309
 
            check_mode(self, 'a', 0666 &~umask)
 
307
            self.assertTransportMode(t, 'a', 0666 &~umask)
310
308
 
311
309
            # but Transport overrides umask
312
310
            t.put('b', 'txt', mode=0666)
313
 
            check_mode(self, 'b', 0666)
 
311
            self.assertTransportMode(t, 'b', 0666)
314
312
 
315
313
            t._sftp.mkdir('c', mode=0777)
316
 
            check_mode(self, 'c', 0777 &~umask)
 
314
            self.assertTransportMode(t, 'c', 0777 &~umask)
317
315
 
318
316
            t.mkdir('d', mode=0777)
319
 
            check_mode(self, 'd', 0777)
 
317
            self.assertTransportMode(t, 'd', 0777)
320
318
        finally:
321
319
            os.umask(original_umask)
322
320