[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-84]
add sftp.normalize kevin c. dorff pointed out that it would be nice to expose a way to determine the server's "current working directory", so this new method (normalize) directly maps to REALPATH.
This commit is contained in:
parent
5176b1ab85
commit
3a4ca74e0a
|
@ -310,9 +310,9 @@ class SFTPClient (BaseSFTP):
|
||||||
relative pathname.
|
relative pathname.
|
||||||
|
|
||||||
@param path: path of the symbolic link file.
|
@param path: path of the symbolic link file.
|
||||||
@type path: string
|
@type path: str
|
||||||
@return: target path.
|
@return: target path.
|
||||||
@rtype: string
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
t, msg = self._request(CMD_READLINK, path)
|
t, msg = self._request(CMD_READLINK, path)
|
||||||
if t != CMD_NAME:
|
if t != CMD_NAME:
|
||||||
|
@ -324,6 +324,26 @@ class SFTPClient (BaseSFTP):
|
||||||
raise SFTPError('Readlink returned %d results' % count)
|
raise SFTPError('Readlink returned %d results' % count)
|
||||||
return msg.get_string()
|
return msg.get_string()
|
||||||
|
|
||||||
|
def normalize(self, path):
|
||||||
|
"""
|
||||||
|
Return the normalized path (on the server) of a given path. This
|
||||||
|
can be used to quickly resolve symbolic links or determine what the
|
||||||
|
server is considering to be the "current folder" (by passing C{'.'}
|
||||||
|
as C{path}).
|
||||||
|
|
||||||
|
@param path: path to be normalized.
|
||||||
|
@type path: str
|
||||||
|
@return: normalized form of the given path.
|
||||||
|
@rtype: str
|
||||||
|
"""
|
||||||
|
t, msg = self._request(CMD_REALPATH, path)
|
||||||
|
if t != CMD_NAME:
|
||||||
|
raise SFTPError('Expected name response')
|
||||||
|
count = msg.get_int()
|
||||||
|
if count != 1:
|
||||||
|
raise SFTPError('Realpath returned %d results' % count)
|
||||||
|
return msg.get_string()
|
||||||
|
|
||||||
|
|
||||||
### internals...
|
### internals...
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue