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
43
# TODO RBC consolidate the helper methods here and in tests/test_permissions.py
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):
51
p = os.path.join(root, d)
54
p = os.path.join(root, f)
55
os.chmod(p, file_mode)
58
def check_mode_r(test, base, file_mode, dir_mode, include_base=True):
59
"""Check that all permissions match
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
67
assert os.path.isdir(base)
68
t = get_transport(".")
70
test.assertTransportMode(t, base, dir_mode)
71
for root, dirs, files in os.walk(base):
73
p = os.path.join(root, d)
74
test.assertTransportMode(t, p, dir_mode)
76
p = os.path.join(root, f)
77
test.assertTransportMode(t, p, file_mode)
80
45
class TestPermissions(TestCaseWithTransport):
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)
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)
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)