~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-26 06:24:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2376.
  • Revision ID: andrew.bennetts@canonical.com-20070326062401-k3nbefzje5332jaf
Deal with review comments from Robert:

  * Add my name to the NEWS file
  * Move the test case to a new module in branch_implementations
  * Remove revision_history cruft from identitymap and test_identitymap
  * Improve some docstrings

Also, this fixes a bug where revision_history was not returning a copy of the
cached data, allowing the cache to be corrupted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    osutils,
34
34
    urlutils,
35
35
    symbol_versioning,
36
 
    transport,
37
36
    )
38
37
from bzrlib.trace import mutter
39
 
from bzrlib.transport import LateReadError
40
38
""")
41
39
 
42
40
from bzrlib.transport import Transport, Server
63
61
            base = urlutils.local_path_to_url(base)
64
62
        if base[-1] != '/':
65
63
            base = base + '/'
66
 
 
67
 
        # Special case : windows has no "root", but does have
68
 
        # multiple lettered drives inside it. #240910
69
 
        if sys.platform == 'win32' and base == 'file:///':
70
 
            base = ''
71
 
            self._local_base = ''
72
 
            super(LocalTransport, self).__init__(base)
73
 
            return
74
 
            
75
64
        super(LocalTransport, self).__init__(base)
76
65
        self._local_base = urlutils.local_path_from_url(base)
77
66
 
 
67
    def should_cache(self):
 
68
        return False
 
69
 
78
70
    def clone(self, offset=None):
79
71
        """Return a new LocalTransport with root at self.base + offset
80
72
        Because the local filesystem does not require a connection, 
105
97
    def abspath(self, relpath):
106
98
        """Return the full url to the given relative URL."""
107
99
        # TODO: url escape the result. RBC 20060523.
 
100
        assert isinstance(relpath, basestring), (type(relpath), relpath)
108
101
        # jam 20060426 Using normpath on the real path, because that ensures
109
102
        #       proper handling of stuff like
110
103
        path = osutils.normpath(osutils.pathjoin(
133
126
            abspath = u'.'
134
127
 
135
128
        return urlutils.file_relpath(
136
 
            urlutils.strip_trailing_slash(self.base),
 
129
            urlutils.strip_trailing_slash(self.base), 
137
130
            urlutils.strip_trailing_slash(abspath))
138
131
 
139
132
    def has(self, relpath):
144
137
 
145
138
        :param relpath: The relative path to the file
146
139
        """
147
 
        canonical_url = self.abspath(relpath)
148
 
        if canonical_url in transport._file_streams:
149
 
            transport._file_streams[canonical_url].flush()
150
140
        try:
151
141
            path = self._abspath(relpath)
152
142
            return open(path, 'rb')
153
143
        except (IOError, OSError),e:
154
 
            if e.errno == errno.EISDIR:
155
 
                return LateReadError(relpath)
156
144
            self._translate_error(e, path)
157
145
 
158
146
    def put_file(self, relpath, f, mode=None):
172
160
        except (IOError, OSError),e:
173
161
            self._translate_error(e, path)
174
162
        try:
175
 
            length = self._pump(f, fp)
 
163
            self._pump(f, fp)
176
164
            fp.commit()
177
165
        finally:
178
166
            fp.close()
179
 
        return length
180
167
 
181
168
    def put_bytes(self, relpath, bytes, mode=None):
182
169
        """Copy the string into the location.
311
298
        """Create a directory at the given path."""
312
299
        self._mkdir(self._abspath(relpath), mode=mode)
313
300
 
314
 
    def open_write_stream(self, relpath, mode=None):
315
 
        """See Transport.open_write_stream."""
316
 
        # initialise the file
317
 
        self.put_bytes_non_atomic(relpath, "", mode=mode)
318
 
        abspath = self._abspath(relpath)
319
 
        handle = open(abspath, 'wb')
320
 
        if mode is not None:
321
 
            self._check_mode_and_size(abspath, handle.fileno(), mode)
322
 
        transport._file_streams[self.abspath(relpath)] = handle
323
 
        return transport.FileFileStream(self, relpath, handle)
324
 
 
325
301
    def _get_append_file(self, relpath, mode=None):
326
302
        """Call os.open() for the given relpath"""
327
303
        file_abspath = self._abspath(relpath)
414
390
        except (IOError, OSError),e:
415
391
            self._translate_error(e, path)
416
392
 
417
 
    def external_url(self):
418
 
        """See bzrlib.transport.Transport.external_url."""
419
 
        # File URL's are externally usable.
420
 
        return self.base
421
 
 
422
393
    def copy_to(self, relpaths, other, mode=None, pb=None):
423
394
        """Copy a set of entries from self into another Transport.
424
395
 
519
490
        self._local_base = urlutils._win32_local_path_from_url(base)
520
491
 
521
492
    def abspath(self, relpath):
 
493
        assert isinstance(relpath, basestring), (type(relpath), relpath)
522
494
        path = osutils.normpath(osutils.pathjoin(
523
495
                    self._local_base, urlutils.unescape(relpath)))
524
496
        return urlutils._win32_local_path_to_url(path)
547
519
    this just exists to tell the test code how to get to it.
548
520
    """
549
521
 
550
 
    def setUp(self):
551
 
        """Setup the server to service requests.
552
 
        
553
 
        :param decorated_transport: ignored by this implementation.
554
 
        """
555
 
 
556
522
    def get_url(self):
557
523
        """See Transport.Server.get_url."""
558
524
        return urlutils.local_path_to_url('')