fixes 1228: rockdbjni loadLibraryFromJarToTemp fails when file is already present (#1232)
overriding existing library in tmp folder
This commit is contained in:
parent
f85df120f2
commit
ee8bf2e41f
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user