1
# Copyright (C) 2005, 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Transport implementation that adapts another transport to look like NFS.
19
Currently this means that the rename() call will raise ResourceBusy when a
20
target path is a directory.
22
To get a fake nfs transport use get_transport('fakenfs+' + real_url)
27
import bzrlib.errors as errors
28
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
31
class FakeNFSTransportDecorator(TransportDecorator):
32
"""A transport that behaves like NFS, for testing"""
35
def _get_url_prefix(self):
36
"""FakeNFS transports are identified by 'fakenfs+'"""
39
def rename(self, rel_from, rel_to):
40
"""See Transport.rename().
42
This variation on rename converts DirectoryNotEmpty and FileExists
43
errors into ResourceBusy if the target is a directory.
46
self._decorated.rename(rel_from, rel_to)
47
except (errors.DirectoryNotEmpty, errors.FileExists), e:
48
# if this is a directory rename, raise
49
# resourcebusy rather than DirectoryNotEmpty
50
stat = self._decorated.stat(rel_to)
51
if S_ISDIR(stat.st_mode):
52
raise errors.ResourceBusy(rel_to)
57
class FakeNFSServer(DecoratorServer):
58
"""Server for the FakeNFSTransportDecorator for testing with."""
60
def get_decorator_class(self):
61
return FakeNFSTransportDecorator
64
def get_test_permutations():
65
"""Return the permutations to be used in testing."""
66
return [(FakeNFSTransportDecorator, FakeNFSServer),