[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
This commit is contained in:
parent
01ca23cace
commit
112b72511e
|
@ -185,7 +185,7 @@ class SFTPClient (BaseSFTP):
|
||||||
if ('w' in mode):
|
if ('w' in mode):
|
||||||
imode |= SFTP_FLAG_CREATE | SFTP_FLAG_TRUNC
|
imode |= SFTP_FLAG_CREATE | SFTP_FLAG_TRUNC
|
||||||
if ('a' in mode):
|
if ('a' in mode):
|
||||||
imode |= SFTP_FLAG_APPEND
|
imode |= SFTP_FLAG_APPEND | SFTP_FLAG_CREATE | SFTP_FLAG_WRITE
|
||||||
attrblock = SFTPAttributes()
|
attrblock = SFTPAttributes()
|
||||||
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
|
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
|
||||||
if t != CMD_HANDLE:
|
if t != CMD_HANDLE:
|
||||||
|
|
|
@ -45,6 +45,15 @@ class SFTPFile (BufferedFile):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def close(self):
|
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)
|
BufferedFile.close(self)
|
||||||
try:
|
try:
|
||||||
self.sftp._request(CMD_CLOSE, self.handle)
|
self.sftp._request(CMD_CLOSE, self.handle)
|
||||||
|
|
Loading…
Reference in New Issue