~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
This is a fairly thin wrapper on regular file IO.
20
20
"""
21
21
 
 
22
from __future__ import absolute_import
 
23
 
22
24
import os
23
25
from stat import ST_MODE, S_ISDIR, S_IMODE
24
26
import sys
72
74
 
73
75
        super(LocalTransport, self).__init__(base)
74
76
        self._local_base = urlutils.local_path_from_url(base)
 
77
        if self._local_base[-1] != '/':
 
78
            self._local_base = self._local_base + '/'
75
79
 
76
80
    def clone(self, offset=None):
77
81
        """Return a new LocalTransport with root at self.base + offset
144
148
        if abspath is None:
145
149
            abspath = u'.'
146
150
 
147
 
        return urlutils.file_relpath(
148
 
            urlutils.strip_trailing_slash(self.base),
149
 
            urlutils.strip_trailing_slash(abspath))
 
151
        return urlutils.file_relpath(self.base, abspath)
150
152
 
151
153
    def has(self, relpath):
152
154
        return os.access(self._abspath(relpath), os.F_OK)
255
257
            if mode is not None and mode != S_IMODE(st.st_mode):
256
258
                # Because of umask, we may still need to chmod the file.
257
259
                # But in the general case, we won't have to
258
 
                os.chmod(abspath, mode)
 
260
                osutils.chmod_if_possible(abspath, mode)
259
261
            writer(fd)
260
262
        finally:
261
263
            os.close(fd)
314
316
            local_mode = mode
315
317
        try:
316
318
            os.mkdir(abspath, local_mode)
317
 
            if mode is not None:
318
 
                # It is probably faster to just do the chmod, rather than
319
 
                # doing a stat, and then trying to compare
320
 
                os.chmod(abspath, mode)
321
319
        except (IOError, OSError),e:
322
320
            self._translate_error(e, abspath)
 
321
        if mode is not None:
 
322
            try:
 
323
                osutils.chmod_if_possible(abspath, mode)
 
324
            except (IOError, OSError), e:
 
325
                self._translate_error(e, abspath)
323
326
 
324
327
    def mkdir(self, relpath, mode=None):
325
328
        """Create a directory at the given path."""
327
330
 
328
331
    def open_write_stream(self, relpath, mode=None):
329
332
        """See Transport.open_write_stream."""
330
 
        # initialise the file
331
 
        self.put_bytes_non_atomic(relpath, "", mode=mode)
332
333
        abspath = self._abspath(relpath)
333
 
        handle = osutils.open_file(abspath, 'wb')
 
334
        try:
 
335
            handle = osutils.open_file(abspath, 'wb')
 
336
        except (IOError, OSError),e:
 
337
            self._translate_error(e, abspath)
 
338
        handle.truncate()
334
339
        if mode is not None:
335
340
            self._check_mode_and_size(abspath, handle.fileno(), mode)
336
341
        transport._file_streams[self.abspath(relpath)] = handle
355
360
        if mode is not None and mode != S_IMODE(st.st_mode):
356
361
            # Because of umask, we may still need to chmod the file.
357
362
            # But in the general case, we won't have to
358
 
            os.chmod(file_abspath, mode)
 
363
            osutils.chmod_if_possible(file_abspath, mode)
359
364
        return st.st_size
360
365
 
361
366
    def append_file(self, relpath, f, mode=None):
454
459
                    otherpath = other._abspath(path)
455
460
                    shutil.copy(mypath, otherpath)
456
461
                    if mode is not None:
457
 
                        os.chmod(otherpath, mode)
 
462
                        osutils.chmod_if_possible(otherpath, mode)
458
463
                except (IOError, OSError),e:
459
464
                    self._translate_error(e, path)
460
465
                count += 1
536
541
            """See Transport.symlink."""
537
542
            abs_link_dirpath = urlutils.dirname(self.abspath(link_name))
538
543
            source_rel = urlutils.file_relpath(
539
 
                urlutils.strip_trailing_slash(abs_link_dirpath),
540
 
                urlutils.strip_trailing_slash(self.abspath(source))
541
 
            )
 
544
                abs_link_dirpath, self.abspath(source))
542
545
 
543
546
            try:
544
547
                os.symlink(source_rel, self._abspath(link_name))
563
566
        self._local_base = urlutils._win32_local_path_from_url(base)
564
567
 
565
568
    def abspath(self, relpath):
566
 
        path = osutils.normpath(osutils.pathjoin(
 
569
        path = osutils._win32_normpath(osutils.pathjoin(
567
570
                    self._local_base, urlutils.unescape(relpath)))
568
571
        return urlutils._win32_local_path_to_url(path)
569
572