-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Lck-File that is correctly deleted on JVM-Exit. #173
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,9 +62,46 @@ public class SQLiteJDBCLoader { | |
* @return True if SQLite native library is successfully loaded; false otherwise. | ||
*/ | ||
public static boolean initialize() throws Exception { | ||
loadSQLiteNativeLibrary(); | ||
return extracted; | ||
// only cleanup before first extract | ||
if(!extracted) { | ||
cleanup(); | ||
} | ||
loadSQLiteNativeLibrary(); | ||
return extracted; | ||
} | ||
|
||
|
||
/** | ||
* Deleted old nativ libraries e.g. on Windows this are not removed on VM-Exit (bug #80) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: native |
||
*/ | ||
static void cleanup(){ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this line |
||
final String ver = org.sqlite.SQLiteJDBCLoader.getVersion(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary final and remove |
||
String tempFolder = new java.io.File(System.getProperty("java.io.tmpdir")).getAbsolutePath(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
java.io.File dir = new java.io.File(tempFolder); | ||
java.io.File [] files = dir.listFiles(new java.io.FilenameFilter() { | ||
@Override | ||
public boolean accept(java.io.File dir, String name) { | ||
return name.startsWith("sqlite-" + ver); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use private variable e.g., |
||
} | ||
}); | ||
|
||
for (java.io.File tempFile : files) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. listFiles can return |
||
if(tempFile.getName().indexOf(".lck") > 0) { continue; } | ||
java.io.File lckFile = new java.io.File(tempFile.getName() + ".lck"); | ||
if(!lckFile.exists()) { | ||
try{ | ||
tempFile.delete(); | ||
} | ||
catch(SecurityException ex){ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swallowing exception is a bad habit. At least we should show the error message here. |
||
} | ||
|
||
} | ||
} | ||
|
||
|
||
} | ||
|
||
/** | ||
* @return True if the SQLite JDBC driver is set to pure Java mode; false otherwise. | ||
|
@@ -181,37 +218,7 @@ private static boolean extractAndLoadLibraryFile(String libFolderForCurrentOS, S | |
extractedLibFile.deleteOnExit(); | ||
extractedLckFile.deleteOnExit(); | ||
|
||
// Add a Shutdown-Hook to remove other unused binaries (dll in temp without lck-file) | ||
Runtime.getRuntime().addShutdownHook(new Thread() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
System.gc(); | ||
final String ver = org.sqlite.SQLiteJDBCLoader.getVersion(); | ||
|
||
String tempFolder = new java.io.File(System.getProperty("java.io.tmpdir")).getAbsolutePath(); | ||
java.io.File dir = new java.io.File(tempFolder); | ||
java.io.File [] files = dir.listFiles(new java.io.FilenameFilter() { | ||
|
||
@Override | ||
public boolean accept(java.io.File dir, String name) | ||
{ | ||
return name.startsWith("sqlite-" + ver); | ||
} | ||
}); | ||
|
||
for (java.io.File tempFile : files) | ||
{ | ||
if(tempFile.getName().indexOf(".lck") > 0) { continue; } | ||
java.io.File lckFile = new java.io.File(tempFile.getName() + ".lck"); | ||
if(!lckFile.exists()){ | ||
tempFile.deleteOnExit(); | ||
} | ||
} | ||
|
||
} | ||
}); | ||
|
||
if(writer != null) { | ||
writer.close(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird indentation