From 73a0df1df3ee3bcda654d383303f2a5771946d41 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Fri, 10 Dec 2004 08:30:44 +0000 Subject: [PATCH] [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.) --- paramiko/sftp_server.py | 4 ++++ paramiko/sftp_si.py | 30 ++++++++++++++++++++++++++++++ tests/test_sftp.py | 1 + 3 files changed, 35 insertions(+) diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py index 22c1f39..11f12c8 100644 --- a/paramiko/sftp_server.py +++ b/paramiko/sftp_server.py @@ -324,6 +324,10 @@ class SFTPServer (BaseSFTP, SubsystemHandler): self._response(request_number, CMD_NAME, 1, resp, '', SFTPAttributes()) else: 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: path = msg.get_string() rpath = self.server.canonicalize(path) diff --git a/paramiko/sftp_si.py b/paramiko/sftp_si.py index 3f77a3f..a65073b 100644 --- a/paramiko/sftp_si.py +++ b/paramiko/sftp_si.py @@ -261,3 +261,33 @@ class SFTPServerInterface (object): else: 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 + diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 64334fb..eebb218 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -295,6 +295,7 @@ class SFTPTest (unittest.TestCase): self.assertEqual(f.readlines(), [ 'original\n' ]) f.close() 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) finally: try: