|
23 | 23 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
24 | 24 | import java.io.File; |
25 | 25 | import static java.io.File.createTempFile; |
| 26 | +import java.io.FileInputStream; |
26 | 27 | import java.io.IOException; |
27 | 28 | import java.io.InputStream; |
28 | 29 | import java.io.OutputStream; |
|
33 | 34 | import static java.util.Locale.ENGLISH; |
34 | 35 | import static java.util.Objects.nonNull; |
35 | 36 | import static java.util.Objects.requireNonNull; |
| 37 | +import java.util.Properties; |
36 | 38 | import static jnr.ffi.LibraryLoader.create; |
37 | 39 | import jnr.ffi.Pointer; |
38 | 40 | import static jnr.ffi.Runtime.getRuntime; |
@@ -97,7 +99,8 @@ final class Library { |
97 | 99 | if (SHOULD_USE_LIB) { |
98 | 100 | libToLoad = getProperty(LMDB_NATIVE_LIB_PROP); |
99 | 101 | } else if (SHOULD_EXTRACT && arch64 && linux) { |
100 | | - libToLoad = extract("org/lmdbjava/lmdbjava-native-linux-x86_64.so"); |
| 102 | + final String flavor = refineLinux(); |
| 103 | + libToLoad = extract(String.format("org/lmdbjava/lmdbjava-native-%s-x86_64.so", flavor)); |
101 | 104 | } else if (SHOULD_EXTRACT && arch64 && osx) { |
102 | 105 | libToLoad = extract("org/lmdbjava/lmdbjava-native-osx-x86_64.dylib"); |
103 | 106 | } else if (SHOULD_EXTRACT && arch64 && windows) { |
@@ -137,6 +140,28 @@ private static String extract(final String name) { |
137 | 140 | } |
138 | 141 | } |
139 | 142 |
|
| 143 | + @SuppressWarnings({"checkstyle:returncount", "PMD.AvoidFileStream"}) |
| 144 | + private static String refineLinux() { |
| 145 | + // /etc/os-release is a very cross-platform way to determine the linux distribution |
| 146 | + // and just happens to be specified in properties format |
| 147 | + try (InputStream inputStream = new FileInputStream("/etc/os-release")) { |
| 148 | + final Properties properties = new Properties(); |
| 149 | + properties.load(inputStream); |
| 150 | + |
| 151 | + final String flavor = String.valueOf(properties.get("ID")).trim(); |
| 152 | + |
| 153 | + // We only care if it's Alpine for now as it uses MUSL instead of GLIBC |
| 154 | + if ("alpine".equals(flavor)) { |
| 155 | + return "linux-alpine"; |
| 156 | + } else { |
| 157 | + return "linux"; |
| 158 | + } |
| 159 | + } catch (final IOException e) { |
| 160 | + // Default to plain 'linux' if anything fails |
| 161 | + return "linux"; |
| 162 | + } |
| 163 | + } |
| 164 | + |
140 | 165 | /** |
141 | 166 | * Structure to wrap a native <code>MDB_envinfo</code>. Not for external use. |
142 | 167 | */ |
|
0 commit comments