From 2d9ec1cf695c0b9e9528be7efccf0cebeed63113 Mon Sep 17 00:00:00 2001 From: lingjie Date: Thu, 19 May 2022 16:44:08 +0800 Subject: [PATCH 1/2] V1.3 Dirent structure add d_namelen field to make compatible with MacOS --- .gitignore | 2 ++ gluster/gfapi/__init__.py | 2 +- gluster/gfapi/api.py | 26 ++++++++++++++++++-------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 193ae00..20ce7c7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ pycscope.* build dist doc/_build +.idea/ +publish.sh \ No newline at end of file diff --git a/gluster/gfapi/__init__.py b/gluster/gfapi/__init__.py index 3372415..79358fa 100644 --- a/gluster/gfapi/__init__.py +++ b/gluster/gfapi/__init__.py @@ -8,7 +8,7 @@ # later), or the GNU General Public License, version 2 (GPLv2), in all # cases as published by the Free Software Foundation. -__version__ = '1.2' +__version__ = '1.3' from .gfapi import File, Dir, DirEntry, Volume __all__ = ['File', 'Dir', 'DirEntry', 'Volume'] diff --git a/gluster/gfapi/api.py b/gluster/gfapi/api.py index e4f0b14..ed83abe 100644 --- a/gluster/gfapi/api.py +++ b/gluster/gfapi/api.py @@ -8,6 +8,7 @@ # later), or the GNU General Public License, version 2 (GPLv2), in all # cases as published by the Free Software Foundation. +import sys import ctypes from ctypes.util import find_library from ctypes import sizeof @@ -105,14 +106,23 @@ class Statvfs (ctypes.Structure): class Dirent (ctypes.Structure): - _fields_ = [ - ("d_ino", ctypes.c_ulong), - ("d_off", ctypes.c_ulong), - ("d_reclen", ctypes.c_ushort), - ("d_type", ctypes.c_char), - ("d_name", ctypes.c_char * 256), - ] - + if sys.platform == 'darwin': + _fields_ = [ + ("d_ino", ctypes.c_ulong), + ("d_off", ctypes.c_ulong), + ("d_reclen", ctypes.c_uint16), + ("d_namelen", ctypes.c_uint16), + ("d_type", ctypes.c_uint8), + ("d_name", ctypes.c_char * 256), + ] + else: + _fields_ = [ + ("d_ino", ctypes.c_ulong), + ("d_off", ctypes.c_ulong), + ("d_reclen", ctypes.c_ushort), + ("d_type", ctypes.c_char), + ("d_name", ctypes.c_char * 256), + ] class Timespec (ctypes.Structure): _fields_ = [ From 7b51a5cacce5659dd0fc586e2cc3c68b6cdc724f Mon Sep 17 00:00:00 2001 From: lingjie Date: Fri, 20 May 2022 11:35:23 +0800 Subject: [PATCH 2/2] V1.4 Stat structure compatible with MacOS --- .gitignore | 3 +- gluster/gfapi/__init__.py | 2 +- gluster/gfapi/api.py | 66 ++++++++++++++++++++++++++++----------- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 20ce7c7..1b263ba 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ build dist doc/_build .idea/ -publish.sh \ No newline at end of file +publish.sh +test/ \ No newline at end of file diff --git a/gluster/gfapi/__init__.py b/gluster/gfapi/__init__.py index 79358fa..ea9daa7 100644 --- a/gluster/gfapi/__init__.py +++ b/gluster/gfapi/__init__.py @@ -8,7 +8,7 @@ # later), or the GNU General Public License, version 2 (GPLv2), in all # cases as published by the Free Software Foundation. -__version__ = '1.3' +__version__ = '1.4' from .gfapi import File, Dir, DirEntry, Volume __all__ = ['File', 'Dir', 'DirEntry', 'Volume'] diff --git a/gluster/gfapi/api.py b/gluster/gfapi/api.py index ed83abe..273f138 100644 --- a/gluster/gfapi/api.py +++ b/gluster/gfapi/api.py @@ -68,24 +68,54 @@ class Stat (ctypes.Structure): - _fields_ = [ - ("st_dev", ctypes.c_ulong), - ("st_ino", ctypes.c_ulong), - ("st_nlink", ctypes.c_ulong), - ("st_mode", ctypes.c_uint), - ("st_uid", ctypes.c_uint), - ("st_gid", ctypes.c_uint), - ("st_rdev", ctypes.c_ulong), - ("st_size", ctypes.c_ulong), - ("st_blksize", ctypes.c_ulong), - ("st_blocks", ctypes.c_ulong), - ("st_atime", ctypes.c_ulong), - ("st_atimensec", ctypes.c_ulong), - ("st_mtime", ctypes.c_ulong), - ("st_mtimensec", ctypes.c_ulong), - ("st_ctime", ctypes.c_ulong), - ("st_ctimensec", ctypes.c_ulong), - ] + if sys.platform == 'darwin': + _fields_ = [ + ("st_dev", ctypes.c_int32), + ("st_mode", ctypes.c_uint16), + ("st_ino", ctypes.c_uint32), + ("st_nlink", ctypes.c_uint16), + ("st_uid", ctypes.c_uint), + ("st_gid", ctypes.c_uint), + ("st_rdev", ctypes.c_uint32), + + ("st_atime", ctypes.c_long), + ("st_atimensec", ctypes.c_long), + ("st_mtime", ctypes.c_long), + ("st_mtimensec", ctypes.c_long), + ("st_ctime", ctypes.c_long), + ("st_ctimensec", ctypes.c_long), + ("st_birthtime", ctypes.c_long), + ("st_birthtimespec", ctypes.c_long), + + ("st_size", ctypes.c_int64), + ("st_blocks", ctypes.c_int64), + ("st_blksize", ctypes.c_int32), + + ("st_flags", ctypes.c_uint32), + ("st_gen", ctypes.c_uint32), + ("st_lspare", ctypes.c_int32), + ("st_qspare1", ctypes.c_int64), + ("st_qspare2", ctypes.c_int64), + ] + else: + _fields_ = [ + ("st_dev", ctypes.c_ulong), + ("st_ino", ctypes.c_ulong), + ("st_nlink", ctypes.c_ulong), + ("st_mode", ctypes.c_uint), + ("st_uid", ctypes.c_uint), + ("st_gid", ctypes.c_uint), + ("st_rdev", ctypes.c_ulong), + ("st_size", ctypes.c_ulong), + ("st_blksize", ctypes.c_ulong), + ("st_blocks", ctypes.c_ulong), + ("st_atime", ctypes.c_ulong), + ("st_atimensec", ctypes.c_ulong), + ("st_mtime", ctypes.c_ulong), + ("st_mtimensec", ctypes.c_ulong), + ("st_ctime", ctypes.c_ulong), + ("st_ctimensec", ctypes.c_ulong), + ] class Statvfs (ctypes.Structure):