Skip to content

Commit 6b0eb2b

Browse files
author
Pan
committed
Implemented SFTP statvfs and SFTP handle fstatvfs methods and integration tests.
Implemented SFTPStatVFS extension class for file system statistics.
1 parent f2a96e8 commit 6b0eb2b

File tree

9 files changed

+2533
-741
lines changed

9 files changed

+2533
-741
lines changed

ssh2/c_sftp.pxd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ cdef extern from "libssh2_sftp.h" nogil:
3030
unsigned long uid, gid
3131
unsigned long permissions
3232
unsigned long atime, mtime
33+
# SFTP statvfs flag bits
34+
enum:
35+
LIBSSH2_SFTP_ST_RDONLY
36+
LIBSSH2_SFTP_ST_NOSUID
3337
ctypedef struct LIBSSH2_SFTP_STATVFS:
34-
uint64_t f_bsize # file system block size
38+
uint64_t f_bsize # file system block size
3539
uint64_t f_frsize # fragment size
3640
uint64_t f_blocks # size of fs in f_frsize units
3741
uint64_t f_bfree # free blocks

ssh2/channel.c

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/session.c

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/sftp.c

Lines changed: 710 additions & 623 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/sftp.pyx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ from error_codes cimport _LIBSSH2_ERROR_EAGAIN, _LIBSSH2_ERROR_BUFFER_TOO_SMALL
2525
from channel cimport Channel, PyChannel
2626
from utils cimport to_bytes, to_str
2727
from exceptions cimport SFTPHandleError, SFTPBufferTooSmall
28-
from sftp_handle cimport SFTPHandle, PySFTPHandle, SFTPAttributes
28+
from sftp_handle cimport SFTPHandle, PySFTPHandle, SFTPAttributes, SFTPStatVFS
2929

3030

3131
# File types
@@ -56,6 +56,9 @@ LIBSSH2_SFTP_S_IROTH = c_sftp.LIBSSH2_SFTP_S_IROTH
5656
LIBSSH2_SFTP_S_IWOTH = c_sftp.LIBSSH2_SFTP_S_IWOTH
5757
LIBSSH2_SFTP_S_IXOTH = c_sftp.LIBSSH2_SFTP_S_IXOTH
5858

59+
LIBSSH2_SFTP_ST_RDONLY = c_sftp.LIBSSH2_SFTP_ST_RDONLY
60+
LIBSSH2_SFTP_ST_NOSUID = c_sftp.LIBSSH2_SFTP_ST_NOSUID
61+
5962

6063
cdef object PySFTP(c_sftp.LIBSSH2_SFTP *sftp, Session session):
6164
cdef SFTP _sftp = SFTP(session)
@@ -179,11 +182,19 @@ cdef class SFTP:
179182
rc = c_sftp.libssh2_sftp_unlink(self._sftp, _filename)
180183
return rc
181184

182-
def fstatvfs(self):
183-
raise NotImplementedError
185+
def statvfs(self, path):
186+
"""Get file system statistics
184187
185-
def statvfs(self):
186-
raise NotImplementedError
188+
:rtype: `ssh2.sftp.SFTPStatVFS` or int of error code"""
189+
cdef SFTPStatVFS vfs = SFTPStatVFS(self)
190+
cdef char *_path = to_bytes(path)
191+
cdef size_t path_len = len(_path)
192+
with nogil:
193+
rc = c_sftp.libssh2_sftp_statvfs(
194+
self._sftp, _path, path_len, vfs._ptr)
195+
if rc != 0:
196+
return rc
197+
return vfs
187198

188199
def mkdir(self, path not None, long mode):
189200
"""Make directory.

0 commit comments

Comments
 (0)