提交 ee8bf2e4 编写于 作者: A Alexander Jipa 提交者: Adam Retter

fixes 1228: rockdbjni loadLibraryFromJarToTemp fails when file is already present (#1232)

overriding existing library in tmp folder
上级 f85df120
......@@ -87,6 +87,10 @@ public class NativeLibraryLoader {
temp = File.createTempFile(tempFilePrefix, tempFileSuffix);
} else {
temp = new File(tmpDir, jniLibraryFileName);
if (temp.exists() && !temp.delete()) {
throw new RuntimeException("File: " + temp.getAbsolutePath()
+ " already exists and cannot be removed.");
}
if (!temp.createNewFile()) {
throw new RuntimeException("File: " + temp.getAbsolutePath()
+ " could not be created.");
......
......@@ -9,6 +9,7 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.rocksdb.util.Environment;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
......@@ -28,4 +29,13 @@ public class NativeLibraryLoaderTest {
assertThat(Files.exists(path)).isTrue();
assertThat(Files.isReadable(path)).isTrue();
}
@Test
public void overridesExistingLibrary() throws IOException {
File first = NativeLibraryLoader.getInstance().loadLibraryFromJarToTemp(
temporaryFolder.getRoot().getAbsolutePath());
NativeLibraryLoader.getInstance().loadLibraryFromJarToTemp(
temporaryFolder.getRoot().getAbsolutePath());
assertThat(first.exists()).isTrue();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册