[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-122]

symlink, readlink
add support for symlink command, and finish support for readlink.  (i guess
i started readlink a while ago but forgot to add the right method to the
SFTPServerInterface class.)
This commit is contained in:
Robey Pointer 2004-12-10 08:30:44 +00:00
parent fa8c4e20bd
commit 73a0df1df3
3 changed files with 35 additions and 0 deletions

View File

@ -324,6 +324,10 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
self._response(request_number, CMD_NAME, 1, resp, '', SFTPAttributes()) self._response(request_number, CMD_NAME, 1, resp, '', SFTPAttributes())
else: else:
self._send_status(request_number, resp) self._send_status(request_number, resp)
elif t == CMD_SYMLINK:
path = msg.get_string()
target_path = msg.get_string()
self._send_status(request_number, self.server.symlink(path, target_path))
elif t == CMD_REALPATH: elif t == CMD_REALPATH:
path = msg.get_string() path = msg.get_string()
rpath = self.server.canonicalize(path) rpath = self.server.canonicalize(path)

View File

@ -261,3 +261,33 @@ class SFTPServerInterface (object):
else: else:
return os.path.normpath('/' + path) return os.path.normpath('/' + path)
def readlink(self, path):
"""
Return the target of a symbolic link (or shortcut) on the server.
If the specified path doesn't refer to a symbolic link, an error
should be returned.
@param path: path (relative or absolute) of the symbolic link.
@type path: str
@return: the target path of the symbolic link, or an error code like
L{SFTP_NO_SUCH_FILE}.
@rtype: str I{or error code}
"""
return SFTP_OP_UNSUPPORTED
def symlink(self, path, target_path):
"""
Create a symbolic link on the server, as new pathname C{path},
with C{target_path} as the target of the link.
@param path: path (relative or absolute) of the symbolic link to
create.
@type path: str
@param target_path: path (relative or absolute) of the target for
this new symbolic link.
@type target_path: str
@return: an error code like C{SFTP_OK}.
@rtype: int
"""
return SFTP_OP_UNSUPPORTED

View File

@ -295,6 +295,7 @@ class SFTPTest (unittest.TestCase):
self.assertEqual(f.readlines(), [ 'original\n' ]) self.assertEqual(f.readlines(), [ 'original\n' ])
f.close() f.close()
self.assertEqual(sftp.lstat(FOLDER + '/link.txt').st_size, 12) self.assertEqual(sftp.lstat(FOLDER + '/link.txt').st_size, 12)
self.assertEqual(sftp.stat(FOLDER + '/link.txt').st_size, 9)
self.assertEqual(sftp.stat(FOLDER + '/original.txt').st_size, 9) self.assertEqual(sftp.stat(FOLDER + '/original.txt').st_size, 9)
finally: finally:
try: try: