24
24
import mmap
25
25
import os
26
26
27
+ import ctypes .util
27
28
from ctypes import c_char_p , c_wchar_p
28
29
from ctypes import c_int , c_longlong
29
30
from ctypes import c_size_t , c_ssize_t
85
86
# keys for plugin-provided locations
86
87
EXTRACTCODE_LIBARCHIVE_LIBDIR = 'extractcode.libarchive.libdir'
87
88
EXTRACTCODE_LIBARCHIVE_DLL = 'extractcode.libarchive.dll'
89
+ _LIBRARY_NAME = 'libarchive'
88
90
89
91
90
92
def load_lib ():
@@ -96,11 +98,17 @@ def load_lib():
96
98
dll = get_location (EXTRACTCODE_LIBARCHIVE_DLL )
97
99
libdir = get_location (EXTRACTCODE_LIBARCHIVE_LIBDIR )
98
100
if not (dll and libdir ) or not os .path .isfile (dll ) or not os .path .isdir (libdir ):
99
- raise Exception (
100
- 'CRITICAL: libarchive DLL is not installed. '
101
- 'Unable to continue: you need to install a valid extractcode-libarchive '
102
- 'plugin with a valid libarchive DLL available.'
103
- )
101
+ filepath = ctypes .util .find_library (_LIBRARY_NAME )
102
+ libarchive = ctypes .cdll .LoadLibrary (filepath )
103
+ if not libarchive :
104
+ raise ImportError (
105
+ 'CRITICAL: libarchive DLL is not installed. '
106
+ 'Unable to continue: you need to install a valid extractcode-libarchive '
107
+ 'plugin with a valid libarchive DLL available '
108
+ 'or to have "libarchive" library installed in your system.'
109
+ )
110
+ logger .warning ('Cannot to use plugin for libarchive, defaulting to system library at ' + filepath )
111
+ return libarchive
104
112
return command .load_shared_library (dll , libdir )
105
113
106
114
0 commit comments