~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
import os
34
34
import sys
35
 
import urllib
36
35
 
37
 
from bzrlib import transport
 
36
from bzrlib import urlutils
38
37
from bzrlib.branch import Branch
39
38
from bzrlib.bzrdir import BzrDir
40
39
from bzrlib.tests import TestCaseWithTransport, TestSkipped
68
67
        test.assertTransportMode(t, base, dir_mode)
69
68
    for root, dirs, files in os.walk(base):
70
69
        for d in dirs:
71
 
            p = '/'.join([urllib.quote(x) for x in root.split('/\\') + [d]])
 
70
            p = '/'.join([urlutils.quote(x) for x in root.split('/\\') + [d]])
72
71
            test.assertTransportMode(t, p, dir_mode)
73
72
        for f in files:
74
73
            p = os.path.join(root, f)
75
 
            p = '/'.join([urllib.quote(x) for x in root.split('/\\') + [f]])
 
74
            p = '/'.join([urlutils.quote(x) for x in root.split('/\\') + [f]])
76
75
            test.assertTransportMode(t, p, file_mode)
77
76
 
78
77
 
84
83
 
85
84
        t = self.make_branch_and_tree('.')
86
85
        b = t.branch
87
 
        open('a', 'wb').write('foo\n')
 
86
        with open('a', 'wb') as f: f.write('foo\n')
88
87
        # ensure check_mode_r works with capital-letter file-ids like TREE_ROOT
89
88
        t.add('a', 'CAPS-ID')
90
89
        t.commit('foo')
105
104
        self.assertEqualMode(0644, b.bzrdir._get_file_mode())
106
105
 
107
106
        # Modifying a file shouldn't break the permissions
108
 
        open('a', 'wb').write('foo2\n')
 
107
        with open('a', 'wb') as f: f.write('foo2\n')
109
108
        t.commit('foo2')
110
109
        # The mode should be maintained after commit
111
110
        check_mode_r(self, '.bzr', 0644, 0755)
112
111
 
113
112
        # Adding a new file should maintain the permissions
114
 
        open('b', 'wb').write('new b\n')
 
113
        with open('b', 'wb') as f: f.write('new b\n')
115
114
        t.add('b')
116
115
        t.commit('new b')
117
116
        check_mode_r(self, '.bzr', 0644, 0755)
126
125
        self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
127
126
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())
128
127
 
129
 
        open('a', 'wb').write('foo3\n')
 
128
        with open('a', 'wb') as f: f.write('foo3\n')
130
129
        t.commit('foo3')
131
130
        check_mode_r(self, '.bzr', 0664, 0775)
132
131
 
133
 
        open('c', 'wb').write('new c\n')
 
132
        with open('c', 'wb') as f: f.write('new c\n')
134
133
        t.add('c')
135
134
        t.commit('new c')
136
135
        check_mode_r(self, '.bzr', 0664, 0775)
158
157
        self.assertEqualMode(02775, b.bzrdir._get_dir_mode())
159
158
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())
160
159
 
161
 
        open('a', 'wb').write('foo4\n')
 
160
        with open('a', 'wb') as f: f.write('foo4\n')
162
161
        t.commit('foo4')
163
162
        check_mode_r(self, '.bzr', 0664, 02775)
164
163
 
165
 
        open('d', 'wb').write('new d\n')
 
164
        with open('d', 'wb') as f: f.write('new d\n')
166
165
        t.add('d')
167
166
        t.commit('new d')
168
167
        check_mode_r(self, '.bzr', 0664, 02775)
183
182
        os.mkdir('local')
184
183
        t_local = self.make_branch_and_tree('local')
185
184
        b_local = t_local.branch
186
 
        open('local/a', 'wb').write('foo\n')
 
185
        with open('local/a', 'wb') as f: f.write('foo\n')
187
186
        t_local.add('a')
188
187
        t_local.commit('foo')
189
188
 
213
212
        self.assertEqualMode(0755, b_sftp.bzrdir._get_dir_mode())
214
213
        self.assertEqualMode(0644, b_sftp.bzrdir._get_file_mode())
215
214
 
216
 
        open('local/a', 'wb').write('foo2\n')
 
215
        with open('local/a', 'wb') as f: f.write('foo2\n')
217
216
        t_local.commit('foo2')
218
217
        b_sftp.pull(b_local)
219
218
        # The mode should be maintained after commit
220
219
        check_mode_r(self, 'sftp/.bzr', 0644, 0755)
221
220
 
222
 
        open('local/b', 'wb').write('new b\n')
 
221
        with open('local/b', 'wb') as f: f.write('new b\n')
223
222
        t_local.add('b')
224
223
        t_local.commit('new b')
225
224
        b_sftp.pull(b_local)
236
235
        self.assertEqualMode(0775, b_sftp.bzrdir._get_dir_mode())
237
236
        self.assertEqualMode(0664, b_sftp.bzrdir._get_file_mode())
238
237
 
239
 
        open('local/a', 'wb').write('foo3\n')
 
238
        with open('local/a', 'wb') as f: f.write('foo3\n')
240
239
        t_local.commit('foo3')
241
240
        b_sftp.pull(b_local)
242
241
        check_mode_r(self, 'sftp/.bzr', 0664, 0775)
243
242
 
244
 
        open('local/c', 'wb').write('new c\n')
 
243
        with open('local/c', 'wb') as f: f.write('new c\n')
245
244
        t_local.add('c')
246
245
        t_local.commit('new c')
247
246
        b_sftp.pull(b_local)