From 14e95e29f34359fc28a3550f6b7ac23a62b48866 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 21 May 2023 14:53:03 +0200 Subject: [PATCH] Fix windows build --- .../java/it/tdlight/util/NativeLibraryLoader.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java b/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java index b4ceecc..995614d 100644 --- a/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java +++ b/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java @@ -15,6 +15,7 @@ */ package it.tdlight.util; +import java.nio.file.AccessDeniedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -263,7 +264,7 @@ public final class NativeLibraryLoader { // We delete the file immediately to free up resources as soon as possible, // and if this fails fallback to deleting on JVM exit. try { - if (tmpFile != null && (!DELETE_NATIVE_LIB_AFTER_LOADING || !Files.deleteIfExists(tmpFile))) { + if (tmpFile != null && (!DELETE_NATIVE_LIB_AFTER_LOADING || !deleteIfExists(tmpFile))) { tmpFile.toFile().deleteOnExit(); } } catch (IOException e) { @@ -272,6 +273,14 @@ public final class NativeLibraryLoader { } } + private static boolean deleteIfExists(Path tmpFile) throws IOException { + try { + return Files.deleteIfExists(tmpFile); + } catch (AccessDeniedException ex) { + return false; + } + } + private static boolean isOsx() { return Native.getOs().equals("osx"); }