Skip to content

Commit

Permalink
support for other db folders on android based on Nozbe#933
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoj committed Feb 6, 2024
1 parent 0580727 commit ab66e27
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ private static SQLiteDatabase createSQLiteDatabase(String name, Context context,
if (name.equals(":memory:") || name.contains("mode=memory")) {
context.getCacheDir().delete();
path = new File(context.getCacheDir(), name).getPath();
}
else if (name.startsWith("/") || name.startsWith("file")) {
// Extracts the database name from the path
val dbName = name.substringAfterLast("/")
if(dbName.contains(".db")){
// Extracts the real path where the *.db file will be created
val directory = name.substringAfterLast("file://").substringBeforeLast("/")

// Creates the directory
val fileObj = File(directory, "databases")
fileObj.mkdir()
File("${directory}/databases", dbName).path
} else {
throw IllegalArgumentException("Database name should contain '.db' as extension")
}
} else {
// On some systems there is some kind of lock on `/databases` folder ¯\_(ツ)_/¯
path = context.getDatabasePath("" + name + ".db").getPath().replace("/databases", "");
Expand Down

0 comments on commit ab66e27

Please sign in to comment.