1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-15 00:21:56 +00:00

create new platform_posix module

move common posix cython code there.
This commit is contained in:
Thomas Waldmann 2016-05-18 16:08:27 +02:00
parent b5404209bb
commit d7500a1191
5 changed files with 16 additions and 19 deletions

View file

@ -1,14 +1,9 @@
import os import os
from .helpers import user2uid, group2gid, safe_decode, safe_encode from .helpers import user2uid, group2gid, safe_decode, safe_encode
from .platform_posix import swidth
API_VERSION = 3 API_VERSION = 3
cdef extern from "wchar.h":
cdef int wcswidth(const Py_UNICODE *str, size_t n)
def swidth(s):
return wcswidth(s, len(s))
cdef extern from "sys/acl.h": cdef extern from "sys/acl.h":
ctypedef struct _acl_t: ctypedef struct _acl_t:
pass pass

View file

@ -1,5 +1,6 @@
import os import os
from .helpers import posix_acl_use_stored_uid_gid, safe_encode, safe_decode from .helpers import posix_acl_use_stored_uid_gid, safe_encode, safe_decode
from .platform_posix import swidth
API_VERSION = 3 API_VERSION = 3
@ -7,12 +8,6 @@ cdef extern from "errno.h":
int errno int errno
int EINVAL int EINVAL
cdef extern from "wchar.h":
cdef int wcswidth(const Py_UNICODE *str, size_t n)
def swidth(s):
return wcswidth(s, len(s))
cdef extern from "sys/types.h": cdef extern from "sys/types.h":
int ACL_TYPE_ACCESS int ACL_TYPE_ACCESS
int ACL_TYPE_DEFAULT int ACL_TYPE_DEFAULT

View file

@ -5,16 +5,12 @@ import stat
from .helpers import posix_acl_use_stored_uid_gid, user2uid, group2gid, safe_decode, safe_encode from .helpers import posix_acl_use_stored_uid_gid, user2uid, group2gid, safe_decode, safe_encode
from .platform_base import SyncFile as BaseSyncFile from .platform_base import SyncFile as BaseSyncFile
from .platform_posix import swidth
from libc cimport errno from libc cimport errno
API_VERSION = 3 API_VERSION = 3
cdef extern from "wchar.h":
cdef int wcswidth(const Py_UNICODE *str, size_t n)
def swidth(s):
return wcswidth(s, len(s))
cdef extern from "sys/types.h": cdef extern from "sys/types.h":
int ACL_TYPE_ACCESS int ACL_TYPE_ACCESS
int ACL_TYPE_DEFAULT int ACL_TYPE_DEFAULT

5
borg/platform_posix.pyx Normal file
View file

@ -0,0 +1,5 @@
cdef extern from "wchar.h":
cdef int wcswidth(const Py_UNICODE *str, size_t n)
def swidth(s):
return wcswidth(s, len(s))

View file

@ -40,6 +40,7 @@ compress_source = 'borg/compress.pyx'
crypto_source = 'borg/crypto.pyx' crypto_source = 'borg/crypto.pyx'
chunker_source = 'borg/chunker.pyx' chunker_source = 'borg/chunker.pyx'
hashindex_source = 'borg/hashindex.pyx' hashindex_source = 'borg/hashindex.pyx'
platform_posix_source = 'borg/platform_posix.pyx'
platform_linux_source = 'borg/platform_linux.pyx' platform_linux_source = 'borg/platform_linux.pyx'
platform_darwin_source = 'borg/platform_darwin.pyx' platform_darwin_source = 'borg/platform_darwin.pyx'
platform_freebsd_source = 'borg/platform_freebsd.pyx' platform_freebsd_source = 'borg/platform_freebsd.pyx'
@ -60,6 +61,7 @@ try:
'borg/crypto.c', 'borg/crypto.c',
'borg/chunker.c', 'borg/_chunker.c', 'borg/chunker.c', 'borg/_chunker.c',
'borg/hashindex.c', 'borg/_hashindex.c', 'borg/hashindex.c', 'borg/_hashindex.c',
'borg/platform_posix.c',
'borg/platform_linux.c', 'borg/platform_linux.c',
'borg/platform_freebsd.c', 'borg/platform_freebsd.c',
'borg/platform_darwin.c', 'borg/platform_darwin.c',
@ -75,13 +77,14 @@ except ImportError:
crypto_source = crypto_source.replace('.pyx', '.c') crypto_source = crypto_source.replace('.pyx', '.c')
chunker_source = chunker_source.replace('.pyx', '.c') chunker_source = chunker_source.replace('.pyx', '.c')
hashindex_source = hashindex_source.replace('.pyx', '.c') hashindex_source = hashindex_source.replace('.pyx', '.c')
platform_posix_source = platform_posix_source.replace('.pyx', '.c')
platform_linux_source = platform_linux_source.replace('.pyx', '.c') platform_linux_source = platform_linux_source.replace('.pyx', '.c')
platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c') platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c')
platform_darwin_source = platform_darwin_source.replace('.pyx', '.c') platform_darwin_source = platform_darwin_source.replace('.pyx', '.c')
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
if not on_rtd and not all(os.path.exists(path) for path in [ if not on_rtd and not all(os.path.exists(path) for path in [
compress_source, crypto_source, chunker_source, hashindex_source, compress_source, crypto_source, chunker_source, hashindex_source,
platform_linux_source, platform_freebsd_source]): platform_posix_source, platform_linux_source, platform_freebsd_source]):
raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.') raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')
@ -286,6 +289,9 @@ if not on_rtd:
Extension('borg.chunker', [chunker_source]), Extension('borg.chunker', [chunker_source]),
Extension('borg.hashindex', [hashindex_source]) Extension('borg.hashindex', [hashindex_source])
] ]
if sys.platform.startswith(('linux', 'freebsd', 'darwin')):
ext_modules.append(Extension('borg.platform_posix', [platform_posix_source]))
if sys.platform == 'linux': if sys.platform == 'linux':
ext_modules.append(Extension('borg.platform_linux', [platform_linux_source], libraries=['acl'])) ext_modules.append(Extension('borg.platform_linux', [platform_linux_source], libraries=['acl']))
elif sys.platform.startswith('freebsd'): elif sys.platform.startswith('freebsd'):