~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

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(
117
110
        This function only exists for the LocalTransport, since it is
118
111
        the only one that has direct local access.
119
112
        This is mostly for stuff like WorkingTree which needs to know
120
 
        the local working directory.  The returned path will always contain
121
 
        forward slashes as the path separator, regardless of the platform.
122
 
 
 
113
        the local working directory.
 
114
        
123
115
        This function is quite expensive: it calls realpath which resolves
124
116
        symlinks.
125
117
        """
134
126
            abspath = u'.'
135
127
 
136
128
        return urlutils.file_relpath(
137
 
            urlutils.strip_trailing_slash(self.base),
 
129
            urlutils.strip_trailing_slash(self.base), 
138
130
            urlutils.strip_trailing_slash(abspath))
139
131
 
140
132
    def has(self, relpath):
145
137
 
146
138
        :param relpath: The relative path to the file
147
139
        """
148
 
        canonical_url = self.abspath(relpath)
149
 
        if canonical_url in transport._file_streams:
150
 
            transport._file_streams[canonical_url].flush()
151
140
        try:
152
141
            path = self._abspath(relpath)
153
142
            return open(path, 'rb')
154
143
        except (IOError, OSError),e:
155
 
            if e.errno == errno.EISDIR:
156
 
                return LateReadError(relpath)
157
144
            self._translate_error(e, path)
158
145
 
159
146
    def put_file(self, relpath, f, mode=None):
173
160
        except (IOError, OSError),e:
174
161
            self._translate_error(e, path)
175
162
        try:
176
 
            length = self._pump(f, fp)
 
163
            self._pump(f, fp)
177
164
            fp.commit()
178
165
        finally:
179
166
            fp.close()
180
 
        return length
181
167
 
182
168
    def put_bytes(self, relpath, bytes, mode=None):
183
169
        """Copy the string into the location.
312
298
        """Create a directory at the given path."""
313
299
        self._mkdir(self._abspath(relpath), mode=mode)
314
300
 
315
 
    def open_write_stream(self, relpath, mode=None):
316
 
        """See Transport.open_write_stream."""
317
 
        # initialise the file
318
 
        self.put_bytes_non_atomic(relpath, "", mode=mode)
319
 
        abspath = self._abspath(relpath)
320
 
        handle = open(abspath, 'wb')
321
 
        if mode is not None:
322
 
            self._check_mode_and_size(abspath, handle.fileno(), mode)
323
 
        transport._file_streams[self.abspath(relpath)] = handle
324
 
        return transport.FileFileStream(self, relpath, handle)
325
 
 
326
301
    def _get_append_file(self, relpath, mode=None):
327
302
        """Call os.open() for the given relpath"""
328
303
        file_abspath = self._abspath(relpath)
415
390
        except (IOError, OSError),e:
416
391
            self._translate_error(e, path)
417
392
 
418
 
    def external_url(self):
419
 
        """See bzrlib.transport.Transport.external_url."""
420
 
        # File URL's are externally usable.
421
 
        return self.base
422
 
 
423
393
    def copy_to(self, relpaths, other, mode=None, pb=None):
424
394
        """Copy a set of entries from self into another Transport.
425
395
 
520
490
        self._local_base = urlutils._win32_local_path_from_url(base)
521
491
 
522
492
    def abspath(self, relpath):
 
493
        assert isinstance(relpath, basestring), (type(relpath), relpath)
523
494
        path = osutils.normpath(osutils.pathjoin(
524
495
                    self._local_base, urlutils.unescape(relpath)))
525
496
        return urlutils._win32_local_path_to_url(path)