~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: Martin Packman
  • Date: 2012-01-05 10:37:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105103758-wzftnmsip5iv9n2g
Revert addition of get_message_encoding function

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
 
73
73
        super(LocalTransport, self).__init__(base)
74
74
        self._local_base = urlutils.local_path_from_url(base)
 
75
        if self._local_base[-1] != '/':
 
76
            self._local_base = self._local_base + '/'
75
77
 
76
78
    def clone(self, offset=None):
77
79
        """Return a new LocalTransport with root at self.base + offset
144
146
        if abspath is None:
145
147
            abspath = u'.'
146
148
 
147
 
        return urlutils.file_relpath(
148
 
            urlutils.strip_trailing_slash(self.base),
149
 
            urlutils.strip_trailing_slash(abspath))
 
149
        return urlutils.file_relpath(self.base, abspath)
150
150
 
151
151
    def has(self, relpath):
152
152
        return os.access(self._abspath(relpath), os.F_OK)
255
255
            if mode is not None and mode != S_IMODE(st.st_mode):
256
256
                # Because of umask, we may still need to chmod the file.
257
257
                # But in the general case, we won't have to
258
 
                os.chmod(abspath, mode)
 
258
                osutils.chmod_if_possible(abspath, mode)
259
259
            writer(fd)
260
260
        finally:
261
261
            os.close(fd)
314
314
            local_mode = mode
315
315
        try:
316
316
            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
317
        except (IOError, OSError),e:
322
318
            self._translate_error(e, abspath)
 
319
        if mode is not None:
 
320
            try:
 
321
                osutils.chmod_if_possible(abspath, mode)
 
322
            except (IOError, OSError), e:
 
323
                self._translate_error(e, abspath)
323
324
 
324
325
    def mkdir(self, relpath, mode=None):
325
326
        """Create a directory at the given path."""
327
328
 
328
329
    def open_write_stream(self, relpath, mode=None):
329
330
        """See Transport.open_write_stream."""
330
 
        # initialise the file
331
 
        self.put_bytes_non_atomic(relpath, "", mode=mode)
332
331
        abspath = self._abspath(relpath)
333
 
        handle = osutils.open_file(abspath, 'wb')
 
332
        try:
 
333
            handle = osutils.open_file(abspath, 'wb')
 
334
        except (IOError, OSError),e:
 
335
            self._translate_error(e, abspath)
 
336
        handle.truncate()
334
337
        if mode is not None:
335
338
            self._check_mode_and_size(abspath, handle.fileno(), mode)
336
339
        transport._file_streams[self.abspath(relpath)] = handle
355
358
        if mode is not None and mode != S_IMODE(st.st_mode):
356
359
            # Because of umask, we may still need to chmod the file.
357
360
            # But in the general case, we won't have to
358
 
            os.chmod(file_abspath, mode)
 
361
            osutils.chmod_if_possible(file_abspath, mode)
359
362
        return st.st_size
360
363
 
361
364
    def append_file(self, relpath, f, mode=None):
454
457
                    otherpath = other._abspath(path)
455
458
                    shutil.copy(mypath, otherpath)
456
459
                    if mode is not None:
457
 
                        os.chmod(otherpath, mode)
 
460
                        osutils.chmod_if_possible(otherpath, mode)
458
461
                except (IOError, OSError),e:
459
462
                    self._translate_error(e, path)
460
463
                count += 1
536
539
            """See Transport.symlink."""
537
540
            abs_link_dirpath = urlutils.dirname(self.abspath(link_name))
538
541
            source_rel = urlutils.file_relpath(
539
 
                urlutils.strip_trailing_slash(abs_link_dirpath),
540
 
                urlutils.strip_trailing_slash(self.abspath(source))
541
 
            )
 
542
                abs_link_dirpath, self.abspath(source))
542
543
 
543
544
            try:
544
545
                os.symlink(source_rel, self._abspath(link_name))
563
564
        self._local_base = urlutils._win32_local_path_from_url(base)
564
565
 
565
566
    def abspath(self, relpath):
566
 
        path = osutils.normpath(osutils.pathjoin(
 
567
        path = osutils._win32_normpath(osutils.pathjoin(
567
568
                    self._local_base, urlutils.unescape(relpath)))
568
569
        return urlutils._win32_local_path_to_url(path)
569
570