~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-06 22:55:29 UTC
  • mfrom: (1946.2.16 reduce-knit-churn)
  • Revision ID: pqm@pqm.ubuntu.com-20060906225529-7b367edabbb1ffc2
(jam) delay creating knit contents for significantly better new commit and push performance

Show diffs side-by-side

added added

removed removed

Lines of Context:
426
426
            raise
427
427
 
428
428
    def _put_non_atomic_helper(self, relpath, writer, mode=None,
429
 
                               create_parent_dir=False):
 
429
                               create_parent_dir=False,
 
430
                               dir_mode=None):
430
431
        abspath = self._remote_path(relpath)
431
432
 
432
433
        # TODO: jam 20060816 paramiko doesn't publicly expose a way to
465
466
            # Try to create the parent directory, and then go back to
466
467
            # writing the file
467
468
            parent_dir = os.path.dirname(abspath)
468
 
            try:
469
 
                self._sftp.mkdir(parent_dir)
470
 
            except (paramiko.SSHException, IOError), e:
471
 
                self._translate_io_exception(e, abspath, ': unable to open')
 
469
            self._mkdir(parent_dir, dir_mode)
472
470
            _open_and_write_file()
473
471
 
474
472
    def put_file_non_atomic(self, relpath, f, mode=None,
475
 
                            create_parent_dir=False):
 
473
                            create_parent_dir=False,
 
474
                            dir_mode=None):
476
475
        """Copy the file-like object into the target location.
477
476
 
478
477
        This function is not strictly safe to use. It is only meant to
491
490
        def writer(fout):
492
491
            self._pump(f, fout)
493
492
        self._put_non_atomic_helper(relpath, writer, mode=mode,
494
 
                                    create_parent_dir=create_parent_dir)
 
493
                                    create_parent_dir=create_parent_dir,
 
494
                                    dir_mode=dir_mode)
495
495
 
496
496
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
497
 
                             create_parent_dir=False):
 
497
                             create_parent_dir=False,
 
498
                             dir_mode=None):
498
499
        def writer(fout):
499
500
            fout.write(bytes)
500
501
        self._put_non_atomic_helper(relpath, writer, mode=mode,
501
 
                                    create_parent_dir=create_parent_dir)
 
502
                                    create_parent_dir=create_parent_dir,
 
503
                                    dir_mode=dir_mode)
502
504
 
503
505
    def iter_files_recursive(self):
504
506
        """Walk the relative paths of all files in this transport."""
512
514
            else:
513
515
                yield relpath
514
516
 
 
517
    def _mkdir(self, abspath, mode=None):
 
518
        if mode is None:
 
519
            local_mode = 0777
 
520
        else:
 
521
            local_mode = mode
 
522
        try:
 
523
            self._sftp.mkdir(abspath, local_mode)
 
524
            if mode is not None:
 
525
                self._sftp.chmod(abspath, mode=mode)
 
526
        except (paramiko.SSHException, IOError), e:
 
527
            self._translate_io_exception(e, abspath, ': unable to mkdir',
 
528
                failure_exc=FileExists)
 
529
 
515
530
    def mkdir(self, relpath, mode=None):
516
531
        """Create a directory at the given path."""
517
 
        path = self._remote_path(relpath)
518
 
        try:
519
 
            self._sftp.mkdir(path)
520
 
            if mode is not None:
521
 
                self._sftp.chmod(path, mode=mode)
522
 
        except (paramiko.SSHException, IOError), e:
523
 
            self._translate_io_exception(e, path, ': unable to mkdir',
524
 
                failure_exc=FileExists)
 
532
        self._mkdir(self._remote_path(relpath), mode=mode)
525
533
 
526
534
    def _translate_io_exception(self, e, path, more_info='', 
527
535
                                failure_exc=PathError):
745
753
            self._translate_io_exception(e, abspath, ': unable to open',
746
754
                failure_exc=FileExists)
747
755
 
 
756
    def _can_roundtrip_unix_modebits(self):
 
757
        if sys.platform == 'win32':
 
758
            # anyone else?
 
759
            return False
 
760
        else:
 
761
            return True
748
762
 
749
763
# ------------- server test implementation --------------
750
764
import threading