/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
38
35
 
 
36
from bzrlib import urlutils
39
37
from bzrlib.branch import Branch
40
38
from bzrlib.bzrdir import BzrDir
41
39
from bzrlib.tests import TestCaseWithTransport, TestSkipped
42
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
43
 
from bzrlib.transport import get_transport
44
41
from bzrlib.workingtree import WorkingTree
45
42
 
46
43
 
65
62
    :param dir_mode: The mode for all directories
66
63
    :param include_base: If false, only check the subdirectories
67
64
    """
68
 
    t = get_transport(".")
 
65
    t = test.get_transport()
69
66
    if include_base:
70
67
        test.assertTransportMode(t, base, dir_mode)
71
68
    for root, dirs, files in os.walk(base):
72
69
        for d in dirs:
73
 
            p = '/'.join([urllib.quote(x) for x in root.split('/\\') + [d]])
 
70
            p = '/'.join([urlutils.quote(x) for x in root.split('/\\') + [d]])
74
71
            test.assertTransportMode(t, p, dir_mode)
75
72
        for f in files:
76
73
            p = os.path.join(root, f)
77
 
            p = '/'.join([urllib.quote(x) for x in root.split('/\\') + [f]])
 
74
            p = '/'.join([urlutils.quote(x) for x in root.split('/\\') + [f]])
78
75
            test.assertTransportMode(t, p, file_mode)
79
76
 
80
77
 
140
137
    def test_new_files_group_sticky_bit(self):
141
138
        if sys.platform == 'win32':
142
139
            raise TestSkipped('chmod has no effect on win32')
143
 
        elif sys.platform == 'darwin' or sys.platform.startswith('freebsd'):
144
 
            # OS X (and FreeBSD) create temp dirs with the 'wheel' group, which
145
 
            # users are not likely to be in, and this prevents us from setting
146
 
            # the sgid bit
 
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
147
144
            os.chown(self.test_dir, os.getuid(), os.getgid())
148
145
 
149
146
        t = self.make_branch_and_tree('.')
180
177
 
181
178
        # bodge around for stubsftpserver not letting use connect
182
179
        # more than once
183
 
        _t = get_transport(self.get_url())
 
180
        _t = self.get_transport()
184
181
 
185
182
        os.mkdir('local')
186
183
        t_local = self.make_branch_and_tree('local')
257
254
        original_umask = os.umask(umask)
258
255
 
259
256
        try:
260
 
            t = get_transport(self.get_url())
 
257
            t = self.get_transport()
261
258
            # Direct access should be masked by umask
262
259
            t._sftp_open_exclusive('a', mode=0666).write('foo\n')
263
260
            self.assertTransportMode(t, 'a', 0666 &~umask)