~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-13 16:23:07 UTC
  • mto: (4634.119.7 2.0)
  • mto: This revision was merged to the branch mainline in revision 4959.
  • Revision ID: john@arbash-meinel.com-20100113162307-0bs82td16gzih827
Update the MANIFEST.in file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
32
32
 
33
33
import os
34
34
import sys
 
35
import stat
 
36
from cStringIO import StringIO
 
37
import urllib
35
38
 
36
 
from bzrlib import urlutils
37
39
from bzrlib.branch import Branch
38
 
from bzrlib.controldir import ControlDir
 
40
from bzrlib.bzrdir import BzrDir
39
41
from bzrlib.tests import TestCaseWithTransport, TestSkipped
40
42
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
43
from bzrlib.transport import get_transport
41
44
from bzrlib.workingtree import WorkingTree
42
45
 
43
46
 
62
65
    :param dir_mode: The mode for all directories
63
66
    :param include_base: If false, only check the subdirectories
64
67
    """
65
 
    t = test.get_transport()
 
68
    t = get_transport(".")
66
69
    if include_base:
67
70
        test.assertTransportMode(t, base, dir_mode)
68
71
    for root, dirs, files in os.walk(base):
69
72
        for d in dirs:
70
 
            p = '/'.join([urlutils.quote(x) for x in root.split('/\\') + [d]])
 
73
            p = '/'.join([urllib.quote(x) for x in root.split('/\\') + [d]])
71
74
            test.assertTransportMode(t, p, dir_mode)
72
75
        for f in files:
73
76
            p = os.path.join(root, f)
74
 
            p = '/'.join([urlutils.quote(x) for x in root.split('/\\') + [f]])
 
77
            p = '/'.join([urllib.quote(x) for x in root.split('/\\') + [f]])
75
78
            test.assertTransportMode(t, p, file_mode)
76
79
 
77
80
 
83
86
 
84
87
        t = self.make_branch_and_tree('.')
85
88
        b = t.branch
86
 
        with open('a', 'wb') as f: f.write('foo\n')
 
89
        open('a', 'wb').write('foo\n')
87
90
        # ensure check_mode_r works with capital-letter file-ids like TREE_ROOT
88
91
        t.add('a', 'CAPS-ID')
89
92
        t.commit('foo')
104
107
        self.assertEqualMode(0644, b.bzrdir._get_file_mode())
105
108
 
106
109
        # Modifying a file shouldn't break the permissions
107
 
        with open('a', 'wb') as f: f.write('foo2\n')
 
110
        open('a', 'wb').write('foo2\n')
108
111
        t.commit('foo2')
109
112
        # The mode should be maintained after commit
110
113
        check_mode_r(self, '.bzr', 0644, 0755)
111
114
 
112
115
        # Adding a new file should maintain the permissions
113
 
        with open('b', 'wb') as f: f.write('new b\n')
 
116
        open('b', 'wb').write('new b\n')
114
117
        t.add('b')
115
118
        t.commit('new b')
116
119
        check_mode_r(self, '.bzr', 0644, 0755)
125
128
        self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
126
129
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())
127
130
 
128
 
        with open('a', 'wb') as f: f.write('foo3\n')
 
131
        open('a', 'wb').write('foo3\n')
129
132
        t.commit('foo3')
130
133
        check_mode_r(self, '.bzr', 0664, 0775)
131
134
 
132
 
        with open('c', 'wb') as f: f.write('new c\n')
 
135
        open('c', 'wb').write('new c\n')
133
136
        t.add('c')
134
137
        t.commit('new c')
135
138
        check_mode_r(self, '.bzr', 0664, 0775)
137
140
    def test_new_files_group_sticky_bit(self):
138
141
        if sys.platform == 'win32':
139
142
            raise TestSkipped('chmod has no effect on win32')
140
 
        elif sys.platform == 'darwin' or 'freebsd' in sys.platform:
141
 
            # FreeBSD-based platforms create temp dirs with the 'wheel' group,
142
 
            # which users are not likely to be in, and this prevents us from
143
 
            # setting the sgid bit
 
143
        elif sys.platform == 'darwin':
 
144
            # OS X creates temp dirs with the 'wheel' group, which users are
 
145
            # not likely to be in, and this prevents us from setting the sgid
 
146
            # bit
144
147
            os.chown(self.test_dir, os.getuid(), os.getgid())
145
148
 
146
149
        t = self.make_branch_and_tree('.')
157
160
        self.assertEqualMode(02775, b.bzrdir._get_dir_mode())
158
161
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())
159
162
 
160
 
        with open('a', 'wb') as f: f.write('foo4\n')
 
163
        open('a', 'wb').write('foo4\n')
161
164
        t.commit('foo4')
162
165
        check_mode_r(self, '.bzr', 0664, 02775)
163
166
 
164
 
        with open('d', 'wb') as f: f.write('new d\n')
 
167
        open('d', 'wb').write('new d\n')
165
168
        t.add('d')
166
169
        t.commit('new d')
167
170
        check_mode_r(self, '.bzr', 0664, 02775)
177
180
 
178
181
        # bodge around for stubsftpserver not letting use connect
179
182
        # more than once
180
 
        _t = self.get_transport()
 
183
        _t = get_transport(self.get_url())
181
184
 
182
185
        os.mkdir('local')
183
186
        t_local = self.make_branch_and_tree('local')
184
187
        b_local = t_local.branch
185
 
        with open('local/a', 'wb') as f: f.write('foo\n')
 
188
        open('local/a', 'wb').write('foo\n')
186
189
        t_local.add('a')
187
190
        t_local.commit('foo')
188
191
 
199
202
 
200
203
        os.mkdir('sftp')
201
204
        sftp_url = self.get_url('sftp')
202
 
        b_sftp = ControlDir.create_branch_and_repo(sftp_url)
 
205
        b_sftp = BzrDir.create_branch_and_repo(sftp_url)
203
206
 
204
207
        b_sftp.pull(b_local)
205
208
        del b_sftp
212
215
        self.assertEqualMode(0755, b_sftp.bzrdir._get_dir_mode())
213
216
        self.assertEqualMode(0644, b_sftp.bzrdir._get_file_mode())
214
217
 
215
 
        with open('local/a', 'wb') as f: f.write('foo2\n')
 
218
        open('local/a', 'wb').write('foo2\n')
216
219
        t_local.commit('foo2')
217
220
        b_sftp.pull(b_local)
218
221
        # The mode should be maintained after commit
219
222
        check_mode_r(self, 'sftp/.bzr', 0644, 0755)
220
223
 
221
 
        with open('local/b', 'wb') as f: f.write('new b\n')
 
224
        open('local/b', 'wb').write('new b\n')
222
225
        t_local.add('b')
223
226
        t_local.commit('new b')
224
227
        b_sftp.pull(b_local)
235
238
        self.assertEqualMode(0775, b_sftp.bzrdir._get_dir_mode())
236
239
        self.assertEqualMode(0664, b_sftp.bzrdir._get_file_mode())
237
240
 
238
 
        with open('local/a', 'wb') as f: f.write('foo3\n')
 
241
        open('local/a', 'wb').write('foo3\n')
239
242
        t_local.commit('foo3')
240
243
        b_sftp.pull(b_local)
241
244
        check_mode_r(self, 'sftp/.bzr', 0664, 0775)
242
245
 
243
 
        with open('local/c', 'wb') as f: f.write('new c\n')
 
246
        open('local/c', 'wb').write('new c\n')
244
247
        t_local.add('c')
245
248
        t_local.commit('new c')
246
249
        b_sftp.pull(b_local)
254
257
        original_umask = os.umask(umask)
255
258
 
256
259
        try:
257
 
            t = self.get_transport()
 
260
            t = get_transport(self.get_url())
258
261
            # Direct access should be masked by umask
259
262
            t._sftp_open_exclusive('a', mode=0666).write('foo\n')
260
263
            self.assertTransportMode(t, 'a', 0666 &~umask)