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

cleanup & docs in sftp
add some more docs to SFTPHandle, and give a default implementation for
close() that's usually right.  add a flush() to the default implementation
of write().  document that symlink's args in the sftp protocol are out of
order (the spec is wrong).
This commit is contained in:
Robey Pointer 2004-12-19 19:43:27 +00:00
parent b2eb38483c
commit 8d127ae8e1
2 changed files with 17 additions and 3 deletions

View File

@ -32,6 +32,9 @@ class SFTPHandle (object):
Abstract object representing a handle to an open file (or folder) on
the server. Each handle has a string representation used by the client
to refer to the underlying file.
Server implementations can (and should) subclass SFTPHandle to implement
features of a file handle, like L{stat} or L{chattr}.
"""
def __init__(self):
self.__name = None
@ -44,8 +47,17 @@ class SFTPHandle (object):
When a client closes a file, this method is called on the handle.
Normally you would use this method to close the underlying OS level
file object(s).
The default implementation checks for attributes on C{self} named
C{readfile} and/or C{writefile}, and if either or both are present,
their C{close()} methods are called. This means that if you are
using the default implementations of L{read} and L{write}, this
method's default implementation should be fine also.
"""
pass
if hasattr(self, 'readfile') and (self.readfile is not None):
self.readfile.close()
if hasattr(self, 'writefile') and (self.writefile is not None):
self.writefile.close()
def read(self, offset, length):
"""
@ -112,6 +124,7 @@ class SFTPHandle (object):
self.writefile.seek(offset)
self.__tell = offset
self.writefile.write(data)
self.writefile.flush()
except IOError, e:
self.__tell = None
return SFTPServer.convert_errno(e.errno)

View File

@ -325,9 +325,10 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
else:
self._send_status(request_number, resp)
elif t == CMD_SYMLINK:
path = msg.get_string()
# the sftp 2 draft is incorrect here! path always follows target_path
target_path = msg.get_string()
self._send_status(request_number, self.server.symlink(path, target_path))
path = msg.get_string()
self._send_status(request_number, self.server.symlink(target_path, path))
elif t == CMD_REALPATH:
path = msg.get_string()
rpath = self.server.canonicalize(path)