~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_permissions.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from bzrlib.bzrdir import BzrDir
37
37
from bzrlib.lockable_files import LockableFiles
38
38
from bzrlib.tests import TestCaseWithTransport, TestSkipped
 
39
from bzrlib.tests.test_permissions import chmod_r, check_mode_r
39
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
41
from bzrlib.transport import get_transport
41
42
from bzrlib.workingtree import WorkingTree
42
43
 
43
 
# TODO RBC consolidate the helper methods here and in tests/test_permissions.py
44
 
 
45
 
def chmod_r(base, file_mode, dir_mode):
46
 
    """Recursively chmod from a base directory"""
47
 
    assert os.path.isdir(base)
48
 
    os.chmod(base, dir_mode)
49
 
    for root, dirs, files in os.walk(base):
50
 
        for d in dirs:
51
 
            p = os.path.join(root, d)
52
 
            os.chmod(p, dir_mode)
53
 
        for f in files:
54
 
            p = os.path.join(root, f)
55
 
            os.chmod(p, file_mode)
56
 
 
57
 
 
58
 
def check_mode_r(test, base, file_mode, dir_mode, include_base=True):
59
 
    """Check that all permissions match
60
 
 
61
 
    :param test: The TestCase being run
62
 
    :param base: The path to the root directory to check
63
 
    :param file_mode: The mode for all files
64
 
    :param dir_mode: The mode for all directories
65
 
    :param include_base: If false, only check the subdirectories
66
 
    """
67
 
    assert os.path.isdir(base)
68
 
    t = get_transport(".")
69
 
    if include_base:
70
 
        test.assertTransportMode(t, base, dir_mode)
71
 
    for root, dirs, files in os.walk(base):
72
 
        for d in dirs:
73
 
            p = os.path.join(root, d)
74
 
            test.assertTransportMode(t, p, dir_mode)
75
 
        for f in files:
76
 
            p = os.path.join(root, f)
77
 
            test.assertTransportMode(t, p, file_mode)
78
 
 
79
44
 
80
45
class TestPermissions(TestCaseWithTransport):
81
46
 
95
60
        b = self.make_branch('b')
96
61
        self.assertEqualMode(02777, b.control_files._dir_mode)
97
62
        self.assertEqualMode(00666, b.control_files._file_mode)
98
 
        check_mode_r(self, b.control_files._transport.base, 00666, 02777)
 
63
        check_mode_r(self, 'b/.bzr', 00666, 02777)
99
64
 
100
65
        os.mkdir('c')
101
66
        os.chmod('c', 02750)
102
67
        b = self.make_branch('c')
103
68
        self.assertEqualMode(02750, b.control_files._dir_mode)
104
69
        self.assertEqualMode(00640, b.control_files._file_mode)
105
 
        check_mode_r(self, b.control_files._transport.base, 00640, 02750)
 
70
        check_mode_r(self, 'c/.bzr', 00640, 02750)
106
71
 
107
72
        os.mkdir('d')
108
73
        os.chmod('d', 0700)
109
74
        b = self.make_branch('d')
110
75
        self.assertEqualMode(0700, b.control_files._dir_mode)
111
76
        self.assertEqualMode(0600, b.control_files._file_mode)
112
 
        check_mode_r(self, b.control_files._transport.base, 00600, 00700)
 
77
        check_mode_r(self, 'd/.bzr', 00600, 00700)