From 1a8ca6688a35384a93f22333bb4002637701494f Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Fri, 10 Jul 2020 14:25:16 -0700 Subject: [PATCH] Make sure directory exists before attempting to write to it (#7090) Summary: Closes https://github.com/facebook/rocksdb/issues/7053 Pull Request resolved: https://github.com/facebook/rocksdb/pull/7090 Reviewed By: riversand963 Differential Revision: D22481199 Pulled By: pdillinger fbshipit-source-id: 287477db94d57b18bee58189135f44936f1c3ca3 --- java/src/main/java/org/rocksdb/NativeLibraryLoader.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/java/src/main/java/org/rocksdb/NativeLibraryLoader.java b/java/src/main/java/org/rocksdb/NativeLibraryLoader.java index 6e37e8cf2..e47eacb22 100644 --- a/java/src/main/java/org/rocksdb/NativeLibraryLoader.java +++ b/java/src/main/java/org/rocksdb/NativeLibraryLoader.java @@ -87,7 +87,12 @@ public class NativeLibraryLoader { if (tmpDir == null || tmpDir.isEmpty()) { temp = File.createTempFile(tempFilePrefix, tempFileSuffix); } else { - temp = new File(tmpDir, jniLibraryFileName); + final File parentDir = new File(tmpDir); + if (!parentDir.exists()) { + throw new RuntimeException( + "Directory: " + parentDir.getAbsolutePath() + " does not exist!"); + } + temp = new File(parentDir, jniLibraryFileName); if (temp.exists() && !temp.delete()) { throw new RuntimeException("File: " + temp.getAbsolutePath() + " already exists and cannot be removed.");