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

overriding existing library in tmp folder
This commit is contained in:
Alexander Jipa 2016-07-24 06:19:00 -04:00 committed by Adam Retter
parent f85df120f2
commit ee8bf2e41f
2 changed files with 14 additions and 0 deletions

View File

@ -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.");

View File

@ -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();
}
}