SQLite: flush database cache entry if file deleted

fbshipit-source-id: ab9107a
This commit is contained in:
Nikhilesh Sigatapu
2017-12-04 19:48:16 +00:00
committed by Exponent GitHub Bot
parent e03766dd45
commit 12aeb4aa6b
2 changed files with 27 additions and 13 deletions

View File

@@ -164,16 +164,21 @@ public class SQLiteModule extends ReactContextBaseJavaModule {
return null;
}
private String pathForDatabaseName(String name) throws IOException {
File directory = new File(mScopedContext.getFilesDir() + File.separator + "SQLite");
ExpFileUtils.ensureDirExists(directory);
return directory + File.separator + name;
}
private SQLiteDatabase getDatabase(String name) throws IOException {
SQLiteDatabase database = DATABASES.get(name);
SQLiteDatabase database = null;
String path = pathForDatabaseName(name);
if ((new File(path)).exists()) {
database = DATABASES.get(name);
}
if (database == null) {
if (":memory:".equals(name)) {
database = SQLiteDatabase.openOrCreateDatabase(name, null);
} else {
File directory = new File(mScopedContext.getFilesDir() + File.separator + "SQLite");
ExpFileUtils.ensureDirExists(directory);
database = SQLiteDatabase.openOrCreateDatabase(directory + File.separator + name, null);
}
DATABASES.remove(name);
database = SQLiteDatabase.openOrCreateDatabase(path, null);
DATABASES.put(name, database);
}
return database;