Rev 3513: Fix ftp transport so that it handles the 'mode' parameter when in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Jun 27 23:53:22 BST 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3513
revision-id:pqm at pqm.ubuntu.com-20080627225315-j2xpbsvjyya1s97y
parent: pqm at pqm.ubuntu.com-20080626004245-dnw85so4xqg8r9hy
parent: v.ladeuil+lp at free.fr-20080627222740-9rat5vruay26xyac
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-06-27 23:53:15 +0100
message:
Fix ftp transport so that it handles the 'mode' parameter when
provided
modified:
bzrlib/tests/ftp_server.py ftpserver.py-20071019102346-61jbvdkrr70igauv-1
bzrlib/transport/ftp.py ftp.py-20051116161804-58dc9506548c2a53
------------------------------------------------------------
revno: 3512.1.1
revision-id:v.ladeuil+lp at free.fr-20080627222740-9rat5vruay26xyac
parent: pqm at pqm.ubuntu.com-20080626004245-dnw85so4xqg8r9hy
parent: v.ladeuil+lp at free.fr-20080627215743-80k2knfo81vrsc8z
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: trunk
timestamp: Sat 2008-06-28 00:27:40 +0200
message:
Fix ftp transport so that it handles the mode parameter when provided
modified:
bzrlib/tests/ftp_server.py ftpserver.py-20071019102346-61jbvdkrr70igauv-1
bzrlib/transport/ftp.py ftp.py-20051116161804-58dc9506548c2a53
------------------------------------------------------------
revno: 3508.1.2
revision-id:v.ladeuil+lp at free.fr-20080627215743-80k2knfo81vrsc8z
parent: v.ladeuil+lp at free.fr-20080627172606-zn1z2ekknau3qa3c
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: fix-chmod
timestamp: Fri 2008-06-27 23:57:43 +0200
message:
Fixed as per John's review.
modified:
bzrlib/tests/ftp_server.py ftpserver.py-20071019102346-61jbvdkrr70igauv-1
------------------------------------------------------------
revno: 3508.1.1
revision-id:v.ladeuil+lp at free.fr-20080627172606-zn1z2ekknau3qa3c
parent: pqm at pqm.ubuntu.com-20080624011313-cq85foncf9mozmen
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: fix-chmod
timestamp: Fri 2008-06-27 19:26:06 +0200
message:
Fix ftp transport so that it handles the 'mode' parameter when provided.
* ftp.py:
(FtpTransport.put_file, FtpTransport.mkdir,
FtpTransport._try_append): Use _setmode.
(FtpTransport._setmode): Fix implementation (parameters were
reversed and mode not converted).
* ftp_server.py:
(test_filesystem): New filesystem implementing chmod.
(test_authorizer.authorize): Use our filesystem when authorized.
(ftp_channel.cmd_site): Implement SITE CHOWN.
modified:
bzrlib/tests/ftp_server.py ftpserver.py-20071019102346-61jbvdkrr70igauv-1
bzrlib/transport/ftp.py ftp.py-20051116161804-58dc9506548c2a53
=== modified file 'bzrlib/tests/ftp_server.py'
--- a/bzrlib/tests/ftp_server.py 2008-04-24 07:22:53 +0000
+++ b/bzrlib/tests/ftp_server.py 2008-06-27 21:57:43 +0000
@@ -37,6 +37,14 @@
)
+class test_filesystem(medusa.filesys.os_filesystem):
+ """A custom filesystem wrapper to add missing functionalities."""
+
+ def chmod(self, path, mode):
+ p = self.normalize(self.path_module.join (self.wd, path))
+ return os.chmod(self.translate(p), mode)
+
+
class test_authorizer(object):
"""A custom Authorizer object for running the test suite.
@@ -64,7 +72,7 @@
and password != self.secured_password):
return 0, 'Password invalid.', None
else:
- return 1, 'OK.', medusa.filesys.os_filesystem(self.root)
+ return 1, 'OK.', test_filesystem(self.root)
class ftp_channel(medusa.ftp_server.ftp_channel):
@@ -153,6 +161,32 @@
except:
self.respond ('550 error creating directory.')
+ def cmd_site(self, line):
+ """Site specific commands."""
+ command, args = line[1].split(' ', 1)
+ if command.lower() == 'chmod':
+ try:
+ mode, path = args.split()
+ mode = int(mode, 8)
+ except ValueError:
+ # We catch both malformed line and malformed mode with the same
+ # ValueError.
+ self.command_not_understood(' '.join(line))
+ return
+ try:
+ # Yes path and mode are reversed
+ self.filesystem.chmod(path, mode)
+ self.respond('200 SITE CHMOD command successful')
+ except AttributeError:
+ # The chmod method is not available in read-only and will raise
+ # AttributeError since a different filesystem is used in that
+ # case
+ self.command_not_authorized(' '.join(line))
+ else:
+ # Another site specific command was requested. We don't know that
+ # one
+ self.command_not_understood(' '.join(line))
+
class ftp_server(medusa.ftp_server.ftp_server):
"""Customize the behavior of the Medusa ftp_server.
=== modified file 'bzrlib/transport/ftp.py'
--- a/bzrlib/transport/ftp.py 2008-05-20 02:25:14 +0000
+++ b/bzrlib/transport/ftp.py 2008-06-27 17:26:06 +0000
@@ -310,6 +310,7 @@
try:
f.storbinary('STOR '+tmp_abspath, fp)
self._rename_and_overwrite(tmp_abspath, abspath, f)
+ self._setmode(relpath, mode)
if bytes is not None:
return len(bytes)
else:
@@ -351,6 +352,7 @@
mutter("FTP mkd: %s", abspath)
f = self._get_FTP()
f.mkd(abspath)
+ self._setmode(relpath, mode)
except ftplib.error_perm, e:
self._translate_perm_error(e, abspath,
unknown_exc=errors.FileExists)
@@ -411,8 +413,7 @@
conn = ftp.transfercmd(cmd)
conn.sendall(text)
conn.close()
- if mode:
- self._setmode(relpath, mode)
+ self._setmode(relpath, mode)
ftp.getresp()
except ftplib.error_perm, e:
self._translate_perm_error(e, abspath, extra='error appending',
@@ -432,16 +433,18 @@
Only set permissions if the FTP server supports the 'SITE CHMOD'
extension.
"""
- try:
- mutter("FTP site chmod: setting permissions to %s on %s",
- str(mode), self._remote_path(relpath))
- ftp = self._get_FTP()
- cmd = "SITE CHMOD %s %s" % (self._remote_path(relpath), str(mode))
- ftp.sendcmd(cmd)
- except ftplib.error_perm, e:
- # Command probably not available on this server
- warning("FTP Could not set permissions to %s on %s. %s",
- str(mode), self._remote_path(relpath), str(e))
+ if mode:
+ try:
+ mutter("FTP site chmod: setting permissions to %s on %s",
+ str(mode), self._remote_path(relpath))
+ ftp = self._get_FTP()
+ cmd = "SITE CHMOD %s %s" % (oct(mode),
+ self._remote_path(relpath))
+ ftp.sendcmd(cmd)
+ except ftplib.error_perm, e:
+ # Command probably not available on this server
+ warning("FTP Could not set permissions to %s on %s. %s",
+ str(mode), self._remote_path(relpath), str(e))
# TODO: jam 20060516 I believe ftp allows you to tell an ftp server
# to copy something to another machine. And you may be able
More information about the bazaar-commits
mailing list