1212import logging
1313import mmap
1414import os
15+ import warnings
1516
17+ import ctypes .util
1618from ctypes import c_char_p , c_wchar_p
1719from ctypes import c_int , c_longlong
1820from ctypes import c_size_t , c_ssize_t
7779
7880EXTRACTCODE_LIBARCHIVE_PATH_ENVVAR = 'EXTRACTCODE_LIBARCHIVE_PATH'
7981
82+ _LIBRARY_NAME = 'libarchive'
83+
8084
8185def load_lib ():
8286 """
@@ -95,17 +99,35 @@ def load_lib():
9599 if not dll_loc :
96100 dll_loc = get_location (EXTRACTCODE_LIBARCHIVE_DLL )
97101
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+
98113 # try the PATH
99114 if not dll_loc :
100115 dll = 'libarchive.dll' if on_windows else 'libarchive.so'
101116 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+ )
102122
103123 if not dll_loc or not os .path .isfile (dll_loc ):
104124 raise Exception (
105125 'CRITICAL: libarchive DLL is not installed. '
106126 'Unable to continue: you need to install a valid extractcode-libarchive '
107127 '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.'
109131 )
110132 return command .load_shared_library (dll_loc )
111133
0 commit comments