sadly, revert the append optimization -- it breaks for openssh
This commit is contained in:
Robey Pointer 2006-09-01 13:59:30 -07:00
parent 1f4a3f1976
commit df20443b29
3 changed files with 8 additions and 15 deletions

View File

@ -296,8 +296,6 @@ class BufferedFile (object):
@return: file position (in bytes). @return: file position (in bytes).
@rtype: int @rtype: int
""" """
if self._flags & self.FLAG_APPEND:
return self._get_size()
return self._pos return self._pos
def write(self, data): def write(self, data):
@ -410,7 +408,8 @@ class BufferedFile (object):
self._flags |= self.FLAG_WRITE self._flags |= self.FLAG_WRITE
if ('a' in mode): if ('a' in mode):
self._flags |= self.FLAG_WRITE | self.FLAG_APPEND 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): if ('b' in mode):
self._flags |= self.FLAG_BINARY self._flags |= self.FLAG_BINARY
if ('U' in mode): if ('U' in mode):
@ -427,8 +426,8 @@ class BufferedFile (object):
count = self._write(data) count = self._write(data)
data = data[count:] data = data[count:]
if self._flags & self.FLAG_APPEND: if self._flags & self.FLAG_APPEND:
# even if we used to know our seek position, we don't now. self._size += count
self._pos = self._realpos = -1 self._pos = self._realpos = self._size
else: else:
self._pos += count self._pos += count
self._realpos += count self._realpos += count

View File

@ -159,11 +159,7 @@ class SFTPFile (BufferedFile):
def _write(self, data): def _write(self, data):
# may write less than requested if it would exceed max packet size # may write less than requested if it would exceed max packet size
chunk = min(len(data), self.MAX_REQUEST_SIZE) chunk = min(len(data), self.MAX_REQUEST_SIZE)
if self._flags & self.FLAG_APPEND: req = self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), str(data[:chunk]))
pos = 0
else:
pos = self._realpos
req = self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(pos), str(data[:chunk]))
if not self.pipelined or self.sftp.sock.recv_ready(): if not self.pipelined or self.sftp.sock.recv_ready():
t, msg = self.sftp._read_response(req) t, msg = self.sftp._read_response(req)
if t != CMD_STATUS: if t != CMD_STATUS:
@ -207,10 +203,6 @@ class SFTPFile (BufferedFile):
def seek(self, offset, whence=0): def seek(self, offset, whence=0):
self.flush() 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: if whence == self.SEEK_SET:
self._realpos = self._pos = offset self._realpos = self._pos = offset
elif whence == self.SEEK_CUR: elif whence == self.SEEK_CUR:

View File

@ -649,9 +649,11 @@ class SFTPTest (unittest.TestCase):
finally: finally:
sftp.unlink(FOLDER + '/zero') 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. verify that seek does't affect writes during append.
does not work except through paramiko. :( openssh fails.
""" """
f = sftp.open(FOLDER + '/append.txt', 'a') f = sftp.open(FOLDER + '/append.txt', 'a')
try: try: