~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

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
146
148
        if abspath is None:
147
149
            abspath = u'.'
148
150
 
149
 
        return urlutils.file_relpath(
150
 
            urlutils.strip_trailing_slash(self.base),
151
 
            urlutils.strip_trailing_slash(abspath))
 
151
        return urlutils.file_relpath(self.base, abspath)
152
152
 
153
153
    def has(self, relpath):
154
154
        return os.access(self._abspath(relpath), os.F_OK)
257
257
            if mode is not None and mode != S_IMODE(st.st_mode):
258
258
                # Because of umask, we may still need to chmod the file.
259
259
                # But in the general case, we won't have to
260
 
                os.chmod(abspath, mode)
 
260
                osutils.chmod_if_possible(abspath, mode)
261
261
            writer(fd)
262
262
        finally:
263
263
            os.close(fd)
316
316
            local_mode = mode
317
317
        try:
318
318
            os.mkdir(abspath, local_mode)
319
 
            if mode is not None:
320
 
                # It is probably faster to just do the chmod, rather than
321
 
                # doing a stat, and then trying to compare
322
 
                os.chmod(abspath, mode)
323
319
        except (IOError, OSError),e:
324
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)
325
326
 
326
327
    def mkdir(self, relpath, mode=None):
327
328
        """Create a directory at the given path."""
330
331
    def open_write_stream(self, relpath, mode=None):
331
332
        """See Transport.open_write_stream."""
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)
334
338
        handle.truncate()
335
339
        if mode is not None:
336
340
            self._check_mode_and_size(abspath, handle.fileno(), mode)
356
360
        if mode is not None and mode != S_IMODE(st.st_mode):
357
361
            # Because of umask, we may still need to chmod the file.
358
362
            # But in the general case, we won't have to
359
 
            os.chmod(file_abspath, mode)
 
363
            osutils.chmod_if_possible(file_abspath, mode)
360
364
        return st.st_size
361
365
 
362
366
    def append_file(self, relpath, f, mode=None):
455
459
                    otherpath = other._abspath(path)
456
460
                    shutil.copy(mypath, otherpath)
457
461
                    if mode is not None:
458
 
                        os.chmod(otherpath, mode)
 
462
                        osutils.chmod_if_possible(otherpath, mode)
459
463
                except (IOError, OSError),e:
460
464
                    self._translate_error(e, path)
461
465
                count += 1
537
541
            """See Transport.symlink."""
538
542
            abs_link_dirpath = urlutils.dirname(self.abspath(link_name))
539
543
            source_rel = urlutils.file_relpath(
540
 
                urlutils.strip_trailing_slash(abs_link_dirpath),
541
 
                urlutils.strip_trailing_slash(self.abspath(source))
542
 
            )
 
544
                abs_link_dirpath, self.abspath(source))
543
545
 
544
546
            try:
545
547
                os.symlink(source_rel, self._abspath(link_name))
564
566
        self._local_base = urlutils._win32_local_path_from_url(base)
565
567
 
566
568
    def abspath(self, relpath):
567
 
        path = osutils.normpath(osutils.pathjoin(
 
569
        path = osutils._win32_normpath(osutils.pathjoin(
568
570
                    self._local_base, urlutils.unescape(relpath)))
569
571
        return urlutils._win32_local_path_to_url(path)
570
572