diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-07-29 13:23:41 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-07-29 13:23:41 +0100 |
commit | b9a9db2fc8ed94ab3f9386259a9e2e31681e9fcc (patch) | |
tree | 5f6fc5ac76613508246a194aee7b11eaa308f0e6 | |
parent | e57864f5f7fa200691177b02fc09a73a7962e9c0 (diff) | |
download | obnam-b9a9db2fc8ed94ab3f9386259a9e2e31681e9fcc.tar.gz |
Fake missing stat fields for sftp.
-rw-r--r-- | obnamlib/plugins/sftp_plugin.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/obnamlib/plugins/sftp_plugin.py b/obnamlib/plugins/sftp_plugin.py index f4510cbf..fc41db58 100644 --- a/obnamlib/plugins/sftp_plugin.py +++ b/obnamlib/plugins/sftp_plugin.py @@ -16,6 +16,7 @@ import errno +import hashlib import logging import os import pwd @@ -284,7 +285,22 @@ class SftpFS(obnamlib.VirtualFileSystem): @ioerror_to_oserror def lstat(self, pathname): - return self.sftp.lstat(pathname) + st = self.sftp.lstat(pathname) + + # SFTP and/or paramiko fail to return some of the required fields, + # so we add them, using faked data. + defaults = { + 'st_blocks': (st.st_size / 512) + + (1 if st.st_size % 512 else 0), + 'st_dev': 0, + 'st_ino': int(hashlib.md5(pathname).hexdigest()[:8], 16), + 'st_nlink': 1, + } + for name, value in defaults.iteritems(): + if not hasattr(st, name): + setattr(st, name, value) + + return st @ioerror_to_oserror def lchown(self, pathname, uid, gid): |