diff options
author | Robey Pointer <robey@lag.net> | 2005-09-18 07:25:54 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2005-09-18 07:25:54 +0000 |
commit | 112b72511eb186175839fc0b8d66b6fc6dcdb534 (patch) | |
tree | 8710b0c944c611d6690e91154da48d18c7058b45 | |
parent | 01ca23cacefd242dba5b5662aa4f46595196588e (diff) |
[project @ Arch-1:robey@lag.net--2005-master-shake%paramiko--dev--1--patch-56]
patch from nathaniel smith: fix SFTPClient.open() 'a' flag, and guard against multiple close() of the same file
-rw-r--r-- | paramiko/sftp_client.py | 2 | ||||
-rw-r--r-- | paramiko/sftp_file.py | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index f0f8fcbf..3a65a688 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -185,7 +185,7 @@ class SFTPClient (BaseSFTP): if ('w' in mode): imode |= SFTP_FLAG_CREATE | SFTP_FLAG_TRUNC if ('a' in mode): - imode |= SFTP_FLAG_APPEND + imode |= SFTP_FLAG_APPEND | SFTP_FLAG_CREATE | SFTP_FLAG_WRITE attrblock = SFTPAttributes() t, msg = self._request(CMD_OPEN, filename, imode, attrblock) if t != CMD_HANDLE: diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index 6b8e9350..854ccf4a 100644 --- a/paramiko/sftp_file.py +++ b/paramiko/sftp_file.py @@ -45,6 +45,15 @@ class SFTPFile (BufferedFile): self.close() def close(self): + # We allow double-close without signaling an error, because real + # Python file objects do. However, we must protect against actually + # sending multiple CMD_CLOSE packets, because after we close our + # handle, the same handle may be re-allocated by the server, and we + # may end up mysteriously closing some random other file. (This is + # especially important because we unconditionally call close() from + # __del__.) + if self._closed: + return BufferedFile.close(self) try: self.sftp._request(CMD_CLOSE, self.handle) |