~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-24 18:26:21 UTC
  • mfrom: (4567 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4568.
  • Revision ID: john@arbash-meinel.com-20090724182621-68s2jhoqf3pn72n7
Merge bzr.dev 4567 to resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
            self.is_active = True
100
100
        else:
101
101
            self.is_active = False
 
102
        
 
103
        # Most modern FTP servers support the APPE command. If ours doesn't, we (re)set this flag accordingly later.
 
104
        self._has_append = True
102
105
 
103
106
    def _get_FTP(self):
104
107
        """Return the ftplib.FTP instance for this object."""
387
390
        """Append the text in the file-like object into the final
388
391
        location.
389
392
        """
 
393
        text = f.read()
 
394
        
390
395
        abspath = self._remote_path(relpath)
391
396
        if self.has(relpath):
392
397
            ftp = self._get_FTP()
394
399
        else:
395
400
            result = 0
396
401
 
397
 
        mutter("FTP appe to %s", abspath)
398
 
        self._try_append(relpath, f.read(), mode)
 
402
        if self._has_append:
 
403
            mutter("FTP appe to %s", abspath)
 
404
            self._try_append(relpath, text, mode)
 
405
        else:
 
406
            self._fallback_append(relpath, text, mode)
399
407
 
400
408
        return result
401
409
 
416
424
            self._setmode(relpath, mode)
417
425
            ftp.getresp()
418
426
        except ftplib.error_perm, e:
419
 
            self._translate_perm_error(e, abspath, extra='error appending',
420
 
                unknown_exc=errors.NoSuchFile)
 
427
            # Check whether the command is not supported (reply code 502)
 
428
            if str(e).startswith('502 '):
 
429
                warning("FTP server does not support file appending natively. " \
 
430
                    "Performance may be severely degraded! (%s)", e)
 
431
                self._has_append = False
 
432
                self._fallback_append(relpath, text, mode)
 
433
            else:
 
434
                self._translate_perm_error(e, abspath, extra='error appending',
 
435
                    unknown_exc=errors.NoSuchFile)
 
436
            
421
437
        except ftplib.error_temp, e:
422
438
            if retries > _number_of_retries:
423
439
                raise errors.TransportError("FTP temporary error during APPEND %s." \
427
443
                self._reconnect()
428
444
                self._try_append(relpath, text, mode, retries+1)
429
445
 
 
446
    def _fallback_append(self, relpath, text, mode = None):
 
447
        remote = self.get(relpath)
 
448
        remote.seek(0, 2)
 
449
        remote.write(text)
 
450
        remote.seek(0, 0)
 
451
        return self.put_file(relpath, remote, mode)
 
452
 
430
453
    def _setmode(self, relpath, mode):
431
454
        """Set permissions on a path.
432
455