From 446dbd57c9d448dc7d0f49dcaf723521736eda0a Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Mon, 22 Jun 2026 17:16:32 +0530 Subject: [PATCH 1/2] Fix #97: Allow custom native library directory via system property --- .../java/com/uber/h3core/H3CoreLoader.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uber/h3core/H3CoreLoader.java b/src/main/java/com/uber/h3core/H3CoreLoader.java index 9533e649..83caad5c 100644 --- a/src/main/java/com/uber/h3core/H3CoreLoader.java +++ b/src/main/java/com/uber/h3core/H3CoreLoader.java @@ -94,16 +94,35 @@ public static NativeMethods loadNatives() throws IOException { } private static File createTempLibraryFile(OperatingSystem os) throws IOException { + // Check if the user specified a custom directory for native libraries + String customDir = System.getProperty("h3.native.dir"); + File dir = customDir != null ? new File(customDir) : null; + + // Ensure the custom directory exists + if (dir != null && !dir.exists()) { + dir.mkdirs(); + } + if (os.isPosix()) { // Note this is already done by the implementation of Files.createTempFile that I looked at, // but the javadoc does not seem to gaurantee the permissions will be restricted to owner // write. final FileAttribute> attr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------")); - return Files.createTempFile("libh3-java", os.getSuffix(), attr).toFile(); + + if (dir != null) { + return Files.createTempFile(dir.toPath(), "libh3-java", os.getSuffix(), attr).toFile(); + } else { + return Files.createTempFile("libh3-java", os.getSuffix(), attr).toFile(); + } } else { // When not a POSIX OS, try to ensure the permissions are secure - final File f = Files.createTempFile("libh3-java", os.getSuffix()).toFile(); + final File f; + if (dir != null) { + f = Files.createTempFile(dir.toPath(), "libh3-java", os.getSuffix()).toFile(); + } else { + f = Files.createTempFile("libh3-java", os.getSuffix()).toFile(); + } f.setReadable(true, true); f.setWritable(true, true); f.setExecutable(true, true); From 023bc51724930dacea276ffb75bbc7d9d9ee0a11 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Mon, 22 Jun 2026 21:55:21 +0530 Subject: [PATCH 2/2] style: apply spotless formatting --- src/main/java/com/uber/h3core/H3CoreLoader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uber/h3core/H3CoreLoader.java b/src/main/java/com/uber/h3core/H3CoreLoader.java index 83caad5c..26a1561f 100644 --- a/src/main/java/com/uber/h3core/H3CoreLoader.java +++ b/src/main/java/com/uber/h3core/H3CoreLoader.java @@ -97,7 +97,7 @@ private static File createTempLibraryFile(OperatingSystem os) throws IOException // Check if the user specified a custom directory for native libraries String customDir = System.getProperty("h3.native.dir"); File dir = customDir != null ? new File(customDir) : null; - + // Ensure the custom directory exists if (dir != null && !dir.exists()) { dir.mkdirs(); @@ -109,7 +109,7 @@ private static File createTempLibraryFile(OperatingSystem os) throws IOException // write. final FileAttribute> attr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------")); - + if (dir != null) { return Files.createTempFile(dir.toPath(), "libh3-java", os.getSuffix(), attr).toFile(); } else {