borg.hashindex: use PyErr_SetFromErrnoWithFilename

instead of home-grown (i.e. not medical grade) OSError raising.
This commit is contained in:
Marian Beermann 2016-05-29 19:52:53 +02:00
parent 9ebb37cab8
commit d1ce746a02
No known key found for this signature in database
GPG key ID: 9B8450B91D1362C1

View file

@ -5,6 +5,8 @@ import os
cimport cython
from libc.stdint cimport uint32_t, UINT32_MAX, uint64_t
from libc.errno cimport errno
from cpython.exc cimport PyErr_SetFromErrnoWithFilename
API_VERSION = 2
@ -28,14 +30,6 @@ cdef extern from "_hashindex.c":
uint32_t _le32toh(uint32_t v)
cdef extern from "errno.h":
int errno
cdef extern from "string.h":
char *strerror(int errnum)
cdef _NoDefault = object()
"""
@ -62,10 +56,6 @@ MAX_VALUE = _MAX_VALUE
assert _MAX_VALUE % 2 == 1
def decoded_strerror(errno):
return strerror(errno).decode(locale.getpreferredencoding(), 'surrogateescape')
@cython.internal
cdef class IndexBase:
cdef HashIndex *index
@ -78,7 +68,8 @@ cdef class IndexBase:
self.index = hashindex_read(path)
if not self.index:
if errno:
raise OSError(errno, decoded_strerror(errno), os.fsdecode(path))
PyErr_SetFromErrnoWithFilename(OSError, path)
return
raise RuntimeError('hashindex_read failed')
else:
self.index = hashindex_init(capacity, self.key_size, self.value_size)