~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-12-20 16:16:34 UTC
  • mfrom: (3123.5.18 hardlinks)
  • Revision ID: pqm@pqm.ubuntu.com-20071220161634-2kcjb650o21ydko4
Accelerate build_tree using similar workingtrees (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
 
90
90
    def __init__(self, base, _from_transport=None):
91
91
        """Set the base path where files will be stored."""
92
 
        if not (base.startswith('ftp://') or base.startswith('aftp://')):
93
 
            raise ValueError(base)
 
92
        assert base.startswith('ftp://') or base.startswith('aftp://')
94
93
        super(FtpTransport, self).__init__(base,
95
94
                                           _from_transport=_from_transport)
96
95
        self._unqualified_scheme = 'ftp'
179
178
            or 'no such dir' in s
180
179
            or 'could not create file' in s # vsftpd
181
180
            or 'file doesn\'t exist' in s
182
 
            or 'rnfr command failed.' in s # vsftpd RNFR reply if file not found
183
181
            or 'file/directory not found' in s # filezilla server
184
 
            # Microsoft FTP-Service RNFR reply if file not found
185
 
            or (s.startswith('550 ') and 'unable to rename to' in extra)
186
182
            ):
187
183
            raise errors.NoSuchFile(path, extra=extra)
188
184
        if ('file exists' in s):
310
306
            try:
311
307
                f.storbinary('STOR '+tmp_abspath, fp)
312
308
                self._rename_and_overwrite(tmp_abspath, abspath, f)
313
 
                self._setmode(relpath, mode)
314
309
                if bytes is not None:
315
310
                    return len(bytes)
316
311
                else:
352
347
            mutter("FTP mkd: %s", abspath)
353
348
            f = self._get_FTP()
354
349
            f.mkd(abspath)
355
 
            self._setmode(relpath, mode)
356
350
        except ftplib.error_perm, e:
357
351
            self._translate_perm_error(e, abspath,
358
352
                unknown_exc=errors.FileExists)
413
407
            conn = ftp.transfercmd(cmd)
414
408
            conn.sendall(text)
415
409
            conn.close()
416
 
            self._setmode(relpath, mode)
 
410
            if mode:
 
411
                self._setmode(relpath, mode)
417
412
            ftp.getresp()
418
413
        except ftplib.error_perm, e:
419
414
            self._translate_perm_error(e, abspath, extra='error appending',
433
428
        Only set permissions if the FTP server supports the 'SITE CHMOD'
434
429
        extension.
435
430
        """
436
 
        if mode:
437
 
            try:
438
 
                mutter("FTP site chmod: setting permissions to %s on %s",
439
 
                    str(mode), self._remote_path(relpath))
440
 
                ftp = self._get_FTP()
441
 
                cmd = "SITE CHMOD %s %s" % (oct(mode),
442
 
                                            self._remote_path(relpath))
443
 
                ftp.sendcmd(cmd)
444
 
            except ftplib.error_perm, e:
445
 
                # Command probably not available on this server
446
 
                warning("FTP Could not set permissions to %s on %s. %s",
447
 
                        str(mode), self._remote_path(relpath), str(e))
 
431
        try:
 
432
            mutter("FTP site chmod: setting permissions to %s on %s",
 
433
                str(mode), self._remote_path(relpath))
 
434
            ftp = self._get_FTP()
 
435
            cmd = "SITE CHMOD %s %s" % (self._remote_path(relpath), str(mode))
 
436
            ftp.sendcmd(cmd)
 
437
        except ftplib.error_perm, e:
 
438
            # Command probably not available on this server
 
439
            warning("FTP Could not set permissions to %s on %s. %s",
 
440
                    str(mode), self._remote_path(relpath), str(e))
448
441
 
449
442
    # TODO: jam 20060516 I believe ftp allows you to tell an ftp server
450
443
    #       to copy something to another machine. And you may be able
519
512
            paths = f.nlst(basepath)
520
513
        except ftplib.error_perm, e:
521
514
            self._translate_perm_error(e, relpath, extra='error with list_dir')
522
 
        except ftplib.error_temp, e:
523
 
            # xs4all's ftp server raises a 450 temp error when listing an empty
524
 
            # directory. Check for that and just return an empty list in that
525
 
            # case. See bug #215522
526
 
            if str(e).lower().startswith('450 no files found'):
527
 
                mutter('FTP Server returned "%s" for nlst.'
528
 
                       ' Assuming it means empty directory',
529
 
                       str(e))
530
 
                return []
531
 
            raise
532
515
        # If FTP.nlst returns paths prefixed by relpath, strip 'em
533
516
        if paths and paths[0].startswith(basepath):
534
517
            entries = [path[len(basepath)+1:] for path in paths]
593
576
        return [(FtpTransport, ftp_server.FTPServer)]
594
577
    else:
595
578
        # Dummy server to have the test suite report the number of tests
596
 
        # needing that feature. We raise UnavailableFeature from methods before
597
 
        # the test server is being used. Doing so in the setUp method has bad
598
 
        # side-effects (tearDown is never called).
 
579
        # needing that feature.
599
580
        class UnavailableFTPServer(object):
600
 
 
601
581
            def setUp(self):
602
 
                pass
603
 
 
604
 
            def tearDown(self):
605
 
                pass
606
 
 
607
 
            def get_url(self):
608
 
                raise tests.UnavailableFeature(tests.FTPServerFeature)
609
 
 
610
 
            def get_bogus_url(self):
611
582
                raise tests.UnavailableFeature(tests.FTPServerFeature)
612
583
 
613
584
        return [(FtpTransport, UnavailableFTPServer)]