summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-12-20 15:50:25 +0100
committerLars Wirzenius <liw@liw.fi>2015-12-20 15:50:25 +0100
commita0eb69f2e54c8517f4bb79484b03fcc6fec0ca9e (patch)
tree1e13a9e1c420376741ba12424191ae2f2162c0d0
parent2e6b7b0b7e812834025afb74f479e91c6382bc96 (diff)
downloadobnam-a0eb69f2e54c8517f4bb79484b03fcc6fec0ca9e.tar.gz
Fix to work with old and new Paramiko prefetch
Found and reported by Kyle Manna.
-rw-r--r--NEWS6
-rw-r--r--obnamlib/plugins/sftp_plugin.py17
2 files changed, 22 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index dcb472eb..b38ec119 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,12 @@ Bug fixes:
won't keep trying to use it, forever. Instead, it crashes and
terminates the backup.
+* The Paramiko SSH implementation, which Obnam uses, changed the
+ interface to the `prefetch` method in its 1.16 version. Obnam can
+ now deal with either variant of the method. Found and reported by
+ Kyle Manna, who provided a patch that Lars Wirzenius rewrote to be
+ backwards compatible to older versions of Paramiko.
+
Improvements to the manual:
* The manual now has an appendix listing all Obnam errors, with codes
diff --git a/obnamlib/plugins/sftp_plugin.py b/obnamlib/plugins/sftp_plugin.py
index c4d5c2f7..66aedf61 100644
--- a/obnamlib/plugins/sftp_plugin.py
+++ b/obnamlib/plugins/sftp_plugin.py
@@ -555,7 +555,7 @@ class SftpFS(obnamlib.VirtualFileSystem):
def cat(self, pathname):
self._delay()
f = self.open(pathname, 'rb')
- f.prefetch()
+ self._prefetch(f)
chunks = []
while True:
chunk = f.read(self.chunk_size)
@@ -566,6 +566,20 @@ class SftpFS(obnamlib.VirtualFileSystem):
f.close()
return ''.join(chunks)
+ def _prefetch(self, f):
+ '''Call f.prefetch in the right way.
+
+ Up to paramiko version 1.15.1, prefetch accepts no arguments.
+ In 1.16 it requires one.
+
+ '''
+
+ if paramiko.__version_info__ < (1, 16):
+ f.prefetch()
+ else:
+ file_size = f.lstat().st_size
+ f.prefetch(file_size)
+
@ioerror_to_oserror
def write_file(self, pathname, contents):
mode = 'wbx'
@@ -588,6 +602,7 @@ class SftpFS(obnamlib.VirtualFileSystem):
f.close()
def _tempfile(self, dirname):
+
'''Create a new file with a random name, return handle and name.'''
if dirname: