12
12
import logging
13
13
import mmap
14
14
import os
15
+ import warnings
15
16
17
+ import ctypes .util
16
18
from ctypes import c_char_p , c_wchar_p
17
19
from ctypes import c_int , c_longlong
18
20
from ctypes import c_size_t , c_ssize_t
77
79
78
80
EXTRACTCODE_LIBARCHIVE_PATH_ENVVAR = 'EXTRACTCODE_LIBARCHIVE_PATH'
79
81
82
+ _LIBRARY_NAME = 'libarchive'
83
+
80
84
81
85
def load_lib ():
82
86
"""
@@ -95,17 +99,35 @@ def load_lib():
95
99
if not dll_loc :
96
100
dll_loc = get_location (EXTRACTCODE_LIBARCHIVE_DLL )
97
101
102
+ # try the standard locations with find_library
103
+ if not dll_loc :
104
+ libarch_loc = ctypes .util .find_library (_LIBRARY_NAME )
105
+ libarchive = ctypes .cdll .LoadLibrary (libarch_loc )
106
+ if libarchive :
107
+ warnings .warn (
108
+ 'Using "libarchive" library found in a system location. '
109
+ 'Install instead a extractcode-libarchive plugin for best support.'
110
+ )
111
+ return libarchive
112
+
98
113
# try the PATH
99
114
if not dll_loc :
100
115
dll = 'libarchive.dll' if on_windows else 'libarchive.so'
101
116
dll_loc = command .find_in_path (dll )
117
+ if dll_loc :
118
+ warnings .warn (
119
+ 'Using "libarchive" library found in the PATH. '
120
+ 'Install instead a extractcode-libarchive plugin for best support.'
121
+ )
102
122
103
123
if not dll_loc or not os .path .isfile (dll_loc ):
104
124
raise Exception (
105
125
'CRITICAL: libarchive DLL is not installed. '
106
126
'Unable to continue: you need to install a valid extractcode-libarchive '
107
127
'plugin with a valid libarchive DLL available. '
108
- f'OR set the { EXTRACTCODE_LIBARCHIVE_PATH_ENVVAR } environment variable.'
128
+ f'OR set the { EXTRACTCODE_LIBARCHIVE_PATH_ENVVAR } environment variable. '
129
+ 'OR install libarchive as a system package. '
130
+ 'OR ensure libarchive is available in the system PATH.'
109
131
)
110
132
return command .load_shared_library (dll_loc )
111
133
0 commit comments