1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
2 |
||
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.
|
|
7 |
||
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.
|
|
12 |
||
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
|
|
16 |
||
17 |
"""Transport implementation that adapts another transport to look like NFS.
|
|
18 |
||
19 |
Currently this means that the rename() call will raise ResourceBusy when a
|
|
20 |
target path is a directory.
|
|
21 |
||
22 |
To get a fake nfs transport use get_transport('fakenfs+' + real_url)
|
|
23 |
"""
|
|
24 |
||
25 |
from stat import * |
|
26 |
||
27 |
import bzrlib.errors as errors |
|
28 |
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer |
|
29 |
||
30 |
||
31 |
class FakeNFSTransportDecorator(TransportDecorator): |
|
32 |
"""A transport that behaves like NFS, for testing"""
|
|
33 |
||
34 |
@classmethod
|
|
35 |
def _get_url_prefix(self): |
|
36 |
"""FakeNFS transports are identified by 'fakenfs+'"""
|
|
37 |
return 'fakenfs+' |
|
38 |
||
39 |
def rename(self, rel_from, rel_to): |
|
40 |
"""See Transport.rename().
|
|
41 |
||
42 |
This variation on rename converts DirectoryNotEmpty and FileExists
|
|
43 |
errors into ResourceBusy if the target is a directory.
|
|
44 |
"""
|
|
45 |
try: |
|
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) |
|
53 |
else: |
|
54 |
raise
|
|
55 |
||
56 |
||
57 |
class FakeNFSServer(DecoratorServer): |
|
58 |
"""Server for the FakeNFSTransportDecorator for testing with."""
|
|
59 |
||
60 |
def get_decorator_class(self): |
|
61 |
return FakeNFSTransportDecorator |
|
62 |
||
63 |
||
64 |
def get_test_permutations(): |
|
65 |
"""Return the permutations to be used in testing."""
|
|
66 |
return [(FakeNFSTransportDecorator, FakeNFSServer), |
|
67 |
]
|