@@ -42,48 +42,59 @@ def get_locations(self):
4242 """
4343 Return a mapping of {location key: location} providing the installation
4444 locations of the libmagic shared library as installed on various Linux
45- distros or on FreeBSD .
45+ distros, FreeBSD, macOS, and other POSIX .
4646 """
4747 mainstream_system = platform .system ().lower ()
48+ system_arch = platform .machine ()
49+ system_arch_bit_width = platform .architecture ()[0 ]
50+
4851 if mainstream_system == 'linux' :
4952 distribution = self .get_like_distro ()
5053 debian_based_distro = ['ubuntu' , 'mint' , 'debian' ]
5154 rpm_based_distro = ['fedora' , 'rhel' ]
52- system_arch = platform .machine ()
5355
5456 if any (dist in debian_based_distro for dist in distribution ):
5557 db_dir = '/usr/lib/file'
5658 lib_dir = (
57- '/usr/lib' if platform . architecture ()[ 0 ] == '32bit'
59+ '/usr/lib' if system_arch_bit_width == '32bit'
5860 else f'/usr/lib/{ system_arch } -linux-gnu'
5961 )
60-
6162 elif any (dist in rpm_based_distro for dist in distribution ):
6263 db_dir = '/usr/share/misc'
6364 lib_dir = (
64- '/usr/lib' if platform . architecture ()[ 0 ] == '32bit'
65+ '/usr/lib' if system_arch_bit_width == '32bit'
6566 else '/usr/lib64'
6667 )
67-
6868 else :
6969 raise Exception ('Unsupported system: {}' .format (distribution ))
7070
7171 dll_loc = path .join (lib_dir , 'libmagic.so.1' )
7272 elif mainstream_system == 'freebsd' :
7373 dll_loc = ''
7474 db_dir = ''
75- for lib_dir in ('/usr/local/' , '/usr' ):
76- possible_dll_loc = path .join (lib_dir , 'lib/libmagic.so' )
77- possible_db_loc = path .join (lib_dir , 'share/misc/magic.mgc' )
75+ for usr_dir in ('/usr/local' , '/usr' ):
76+ lib_dir = path .join (usr_dir , 'lib' )
77+ possible_dll_loc = path .join (lib_dir , 'libmagic.so' )
78+ possible_db_loc = path .join (usr_dir , 'share/misc/magic.mgc' )
7879 if path .exists (possible_dll_loc ) and path .exists (possible_db_loc ):
7980 dll_loc = possible_dll_loc
8081 db_dir = path .dirname (possible_db_loc )
8182 break
8283 elif mainstream_system == 'darwin' :
8384 # This assumes that libmagic was installed using Homebrew
84- lib_dir = '/opt/homebrew'
85- dll_loc = path .join (lib_dir , 'lib/libmagic.dylib' )
86- db_dir = path .join (lib_dir , 'share/misc' )
85+ lib_dir = '/opt/homebrew/lib'
86+ dll_loc = path .join (lib_dir , 'libmagic.dylib' )
87+ db_dir = '/opt/homebrew/share/misc'
88+ elif mainstream_system == 'sunos' :
89+ lib_dir = '/usr/lib'
90+ if system_arch == 'i86pc' and system_arch_bit_width == '64bit' :
91+ lib_dir = path .join (lib_dir , 'amd64' )
92+ dll_loc = path .join (lib_dir , 'libmagic.so' )
93+ db_dir = '/usr/share/misc'
94+ elif mainstream_system == 'haiku' :
95+ lib_dir = '/system/lib'
96+ dll_loc = path .join (lib_dir , 'libmagic.so.1' )
97+ db_dir = '/system/data/misc'
8798
8899 magicdb_loc = path .join (db_dir , 'magic.mgc' )
89100
0 commit comments