Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_locations(self):
"""
Return a mapping of {location key: location} providing the installation
locations of the 7zip exe and shared libraries as installed on various
Linux distros or on FreeBSD.
Linux distros, FreeBSD, macOS, and other POSIX.
"""
lib_dir = None
lib_7z = environ.get('EXTRACTCODE_7Z_PATH')
Expand Down Expand Up @@ -62,6 +62,12 @@ def get_locations(self):
# This assumes that 7zip was installed using Homebrew
lib_dir = '/opt/homebrew/bin'
lib_7z = path.join(lib_dir, '7zz')
elif mainstream_system == 'sunos':
lib_dir = '/usr/bin'
lib_7z = path.join(lib_dir, '7z')
elif mainstream_system == 'haiku':
lib_dir = '/bin'
lib_7z = path.join(lib_dir, '7z')
else:
lib_dir = path.dirname(lib_7z)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def get_locations(self):
"""
Return a mapping of {location key: location} providing the installation
locations of the libarchive shared library as installed on various Linux
distros or on FreeBSD.
distros, FreeBSD, macOS, and other POSIX.
"""
lib_archive = environ.get('EXTRACTCODE_LIBARCHIVE_PATH')
if not lib_archive:
system_arch = platform.machine()
mainstream_system = platform.system().lower()
system_arch = platform.machine()
system_arch_bit_width = platform.architecture()[0]

if mainstream_system == 'linux':
distribution = self.get_like_distro()
Expand All @@ -42,16 +43,14 @@ def get_locations(self):

if any(dist in debian_based_distro for dist in distribution):
lib_dir = (
'/usr/lib' if platform.architecture()[0] == '32bit'
'/usr/lib' if system_arch_bit_width == '32bit'
else f'/usr/lib/{system_arch}-linux-gnu'
)

elif any(dist in rpm_based_distro for dist in distribution):
lib_dir = (
'/usr/lib' if platform.architecture()[0] == '32bit'
'/usr/lib' if system_arch_bit_width == '32bit'
else '/usr/lib64'
)

else:
raise Exception(
'Unsupported system: {}'.format(distribution))
Expand All @@ -68,6 +67,14 @@ def get_locations(self):
# This assumes that libarchive was installed using Homebrew
lib_dir = '/opt/homebrew/opt/libarchive/lib'
lib_archive = path.join(lib_dir, 'libarchive.dylib')
elif mainstream_system == 'sunos':
lib_dir = '/usr/lib'
if system_arch == 'i86pc' and system_arch_bit_width == '64bit':
lib_dir = path.join(lib_dir, 'amd64')
lib_archive = path.join(lib_dir, 'libarchive.so')
elif mainstream_system == 'haiku':
lib_dir = '/system/lib'
lib_archive = path.join(lib_dir, 'libarchive.so.13')
else:
lib_dir = path.dirname(lib_archive)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,48 +42,59 @@ def get_locations(self):
"""
Return a mapping of {location key: location} providing the installation
locations of the libmagic shared library as installed on various Linux
distros or on FreeBSD.
distros, FreeBSD, macOS, and other POSIX.
"""
mainstream_system = platform.system().lower()
system_arch = platform.machine()
system_arch_bit_width = platform.architecture()[0]

if mainstream_system == 'linux':
distribution = self.get_like_distro()
debian_based_distro = ['ubuntu', 'mint', 'debian']
rpm_based_distro = ['fedora', 'rhel']
system_arch = platform.machine()

if any(dist in debian_based_distro for dist in distribution):
db_dir = '/usr/lib/file'
lib_dir = (
'/usr/lib' if platform.architecture()[0] == '32bit'
'/usr/lib' if system_arch_bit_width == '32bit'
else f'/usr/lib/{system_arch}-linux-gnu'
)

elif any(dist in rpm_based_distro for dist in distribution):
db_dir = '/usr/share/misc'
lib_dir = (
'/usr/lib' if platform.architecture()[0] == '32bit'
'/usr/lib' if system_arch_bit_width == '32bit'
else '/usr/lib64'
)

else:
raise Exception('Unsupported system: {}'.format(distribution))

dll_loc = path.join(lib_dir, 'libmagic.so.1')
elif mainstream_system == 'freebsd':
dll_loc = ''
db_dir = ''
for lib_dir in ('/usr/local/', '/usr'):
possible_dll_loc = path.join(lib_dir, 'lib/libmagic.so')
possible_db_loc = path.join(lib_dir, 'share/misc/magic.mgc')
for usr_dir in ('/usr/local', '/usr'):
lib_dir = path.join(usr_dir, 'lib')
possible_dll_loc = path.join(lib_dir, 'libmagic.so')
possible_db_loc = path.join(usr_dir, 'share/misc/magic.mgc')
if path.exists(possible_dll_loc) and path.exists(possible_db_loc):
dll_loc = possible_dll_loc
db_dir = path.dirname(possible_db_loc)
break
elif mainstream_system == 'darwin':
# This assumes that libmagic was installed using Homebrew
lib_dir = '/opt/homebrew'
dll_loc = path.join(lib_dir, 'lib/libmagic.dylib')
db_dir = path.join(lib_dir, 'share/misc')
lib_dir = '/opt/homebrew/lib'
dll_loc = path.join(lib_dir, 'libmagic.dylib')
db_dir = '/opt/homebrew/share/misc'
elif mainstream_system == 'sunos':
lib_dir = '/usr/lib'
if system_arch == 'i86pc' and system_arch_bit_width == '64bit':
lib_dir = path.join(lib_dir, 'amd64')
dll_loc = path.join(lib_dir, 'libmagic.so')
db_dir = '/usr/share/misc'
elif mainstream_system == 'haiku':
lib_dir = '/system/lib'
dll_loc = path.join(lib_dir, 'libmagic.so.1')
db_dir = '/system/data/misc'

magicdb_loc = path.join(db_dir, 'magic.mgc')

Expand Down