1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
1
# Copyright (C) 2005, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
from StringIO import StringIO
24
from bzrlib import tests, ui
25
21
from bzrlib.bzrdir import (
46
42
BzrDir.create_standalone_workingtree('branch')
47
43
os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
48
44
os.mkdir('no-die-please')
49
self.assertPathExists('branch/die-please')
45
self.failUnlessExists('branch/die-please')
50
46
os.mkdir('no-die-please/child')
52
48
clean_tree('branch', unknown=True, no_prompt=True)
53
self.assertPathExists('no-die-please')
54
self.assertPathExists('no-die-please/child')
49
self.failUnlessExists('no-die-please')
50
self.failUnlessExists('no-die-please/child')
56
52
def test_iter_deletable(self):
57
53
"""Files are selected for deletion appropriately"""
80
76
self.assertEqual([], dels)
84
def test_delete_items_warnings(self):
85
"""Ensure delete_items issues warnings on EACCES. (bug #430785)
87
def _dummy_unlink(path):
88
"""unlink() files other than files named '0foo'.
90
if path.endswith('0foo'):
91
# Simulate 'permission denied' error.
92
# This should show up as a warning for the
95
e.errno = errno.EACCES
98
def _dummy_rmtree(path, ignore_errors=False, onerror=None):
99
"""Call user supplied error handler onerror.
101
# Indicate failure in removing 'path' if path is subdir0
102
# We later check to ensure that this is indicated
103
# to the user as a warning. We raise OSError to construct
104
# proper excinfo that needs to be passed to onerror
108
e.errno = errno.EACCES
109
excinfo = sys.exc_info()
111
if 'subdir0' not in path:
112
# onerror should show warning only for os.remove
113
# error. For any other failures the error should
114
# be shown to the user.
115
function = os.listdir
116
onerror(function=function,
117
path=path, excinfo=excinfo)
119
self.overrideAttr(os, 'unlink', _dummy_unlink)
120
self.overrideAttr(shutil, 'rmtree', _dummy_rmtree)
121
stdout = tests.StringIOWrapper()
122
stderr = tests.StringIOWrapper()
123
ui.ui_factory = tests.TestUIFactory(stdout=stdout, stderr=stderr)
125
BzrDir.create_standalone_workingtree('.')
126
self.build_tree(['0foo', '1bar', '2baz', 'subdir0/'])
127
clean_tree('.', unknown=True, no_prompt=True)
128
self.assertContainsRe(stderr.getvalue(),
129
'bzr: warning: unable to remove.*0foo')
130
self.assertContainsRe(stderr.getvalue(),
131
'bzr: warning: unable to remove.*subdir0')
133
# Ensure that error other than EACCES during os.remove are
134
# not turned into warnings.
135
self.build_tree(['subdir1/'])
136
self.assertRaises(OSError, clean_tree, '.',
137
unknown=True, no_prompt=True)