summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2006-09-01 13:59:30 -0700
committerRobey Pointer <robey@lag.net>2006-09-01 13:59:30 -0700
commitdf20443b29b0da3e8ad0ebbdab07ed8573406790 (patch)
tree034fdf041183640425436b304f61e977e2e6c14a
parent1f4a3f19764bdc7483ae503a946e631681ab3e6e (diff)
downloadparamiko-df20443b29b0da3e8ad0ebbdab07ed8573406790.tar.gz
[project @ robey@lag.net-20060901205930-021bcc34e3d5d8c8]
sadly, revert the append optimization -- it breaks for openssh
-rw-r--r--paramiko/file.py9
-rw-r--r--paramiko/sftp_file.py10
-rwxr-xr-xtests/test_sftp.py4
3 files changed, 8 insertions, 15 deletions
diff --git a/paramiko/file.py b/paramiko/file.py
index 98a28f6f..1c151af4 100644
--- a/paramiko/file.py
+++ b/paramiko/file.py
@@ -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
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py
index e29d5574..13ac1754 100644
--- a/paramiko/sftp_file.py
+++ b/paramiko/sftp_file.py
@@ -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:
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index db210131..a4603367 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -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: