Document FTP: fix walking utf8 paths.

Also fix the error message when rename fails for utf8 filenames.

bzr revid: p_christ@hol.gr-20100708225213-fcq2nbgectztjycq
This commit is contained in:
P. Christeas 2010-07-09 01:52:13 +03:00
parent 819eed88a2
commit e7d01ae1e3
2 changed files with 18 additions and 4 deletions

View File

@ -278,7 +278,7 @@ class abstracted_fs(object):
if path == '/' and mode in ('list', 'cwd'):
return (None, None, None )
path = os.path.normpath(path) # again, for '/db/../ss'
path = _to_unicode(os.path.normpath(path)) # again, for '/db/../ss'
if path == '.': path = ''
if os.path.isabs(path) and self.cwd_node is not None \

View File

@ -221,6 +221,17 @@ def _strerror(err):
else:
return err.strerror
def _to_unicode(s):
try:
return s.decode('utf-8')
except UnicodeError:
try:
return s.decode('latin')
except UnicodeError:
try:
return s.encode('ascii')
except UnicodeError:
return s
# --- library defined exceptions
@ -2650,15 +2661,18 @@ class FTPHandler(asynchat.async_chat):
try:
try:
datacr = self.fs.get_crdata(line,'create')
oldname = '/'.join(self.fs.rnfr.path)
oldname = self.fs.rnfr.path
if isinstance(oldname, (list, tuple)):
oldname = '/'.join(oldname)
self.run_as_current_user(self.fs.rename, self.fs.rnfr, datacr)
self.fs.rnfr = None
self.log('OK RNFR/RNTO "%s ==> %s".' %(oldname, line))
self.log('OK RNFR/RNTO "%s ==> %s".' % \
(_to_unicode(oldname), _to_unicode(line)))
self.respond("250 Renaming ok.")
except EnvironmentError, err:
why = _strerror(err)
self.log('FAIL RNFR/RNTO "%s ==> %s". %s.' \
%(self.fs.ftpnorm(self.fs.rnfr), line, why))
% (_to_unicode(oldname), _to_unicode(line), why))
self.respond('550 %s.' %why)
finally:
self.fs.rnfr = None