sadly, revert the append optimization -- it breaks for openssh
This commit is contained in:
parent
1f4a3f1976
commit
df20443b29
|
@ -296,8 +296,6 @@ class BufferedFile (object):
|
|||
@return: file position (in bytes).
|
||||
@rtype: int
|
||||
"""
|
||||
if self._flags & self.FLAG_APPEND:
|
||||
return self._get_size()
|
||||
return self._pos
|
||||
|
||||
def write(self, data):
|
||||
|
@ -410,7 +408,8 @@ class BufferedFile (object):
|
|||
self._flags |= self.FLAG_WRITE
|
||||
if ('a' in mode):
|
||||
self._flags |= self.FLAG_WRITE | self.FLAG_APPEND
|
||||
self._pos = self._realpos = -1
|
||||
self._size = self._get_size()
|
||||
self._pos = self._realpos = self._size
|
||||
if ('b' in mode):
|
||||
self._flags |= self.FLAG_BINARY
|
||||
if ('U' in mode):
|
||||
|
@ -427,8 +426,8 @@ class BufferedFile (object):
|
|||
count = self._write(data)
|
||||
data = data[count:]
|
||||
if self._flags & self.FLAG_APPEND:
|
||||
# even if we used to know our seek position, we don't now.
|
||||
self._pos = self._realpos = -1
|
||||
self._size += count
|
||||
self._pos = self._realpos = self._size
|
||||
else:
|
||||
self._pos += count
|
||||
self._realpos += count
|
||||
|
|
|
@ -159,11 +159,7 @@ class SFTPFile (BufferedFile):
|
|||
def _write(self, data):
|
||||
# may write less than requested if it would exceed max packet size
|
||||
chunk = min(len(data), self.MAX_REQUEST_SIZE)
|
||||
if self._flags & self.FLAG_APPEND:
|
||||
pos = 0
|
||||
else:
|
||||
pos = self._realpos
|
||||
req = self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(pos), str(data[:chunk]))
|
||||
req = self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), str(data[:chunk]))
|
||||
if not self.pipelined or self.sftp.sock.recv_ready():
|
||||
t, msg = self.sftp._read_response(req)
|
||||
if t != CMD_STATUS:
|
||||
|
@ -207,10 +203,6 @@ class SFTPFile (BufferedFile):
|
|||
|
||||
def seek(self, offset, whence=0):
|
||||
self.flush()
|
||||
if (self._flags & self.FLAG_APPEND) and (self._realpos == -1) and (whence != self.SEEK_END):
|
||||
# this is still legal for O_RDWR ('a+'), but we need to figure out
|
||||
# where we are -- we lost track of it during writes.
|
||||
self._realpos = self._pos = self._get_size()
|
||||
if whence == self.SEEK_SET:
|
||||
self._realpos = self._pos = offset
|
||||
elif whence == self.SEEK_CUR:
|
||||
|
|
|
@ -649,9 +649,11 @@ class SFTPTest (unittest.TestCase):
|
|||
finally:
|
||||
sftp.unlink(FOLDER + '/zero')
|
||||
|
||||
def test_M_seek_append(self):
|
||||
def XXX_test_M_seek_append(self):
|
||||
"""
|
||||
verify that seek does't affect writes during append.
|
||||
|
||||
does not work except through paramiko. :( openssh fails.
|
||||
"""
|
||||
f = sftp.open(FOLDER + '/append.txt', 'a')
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue