Make sure there is enough storage space for VACUUM

This commit is contained in:
M66B 2020-01-21 08:42:11 +01:00
parent 3236591e31
commit ed5751b3b4
1 changed files with 7 additions and 2 deletions

View File

@ -224,8 +224,13 @@ public class WorkerCleanup extends Worker {
if (manual) {
// https://www.sqlite.org/lang_vacuum.html
Log.i("Running VACUUM");
db.getOpenHelper().getWritableDatabase().execSQL("VACUUM;");
long size = context.getDatabasePath(db.getOpenHelper().getDatabaseName()).length();
long space = Helper.getAvailableStorageSpace();
if (size * 2 < space) {
Log.i("Running VACUUM");
db.getOpenHelper().getWritableDatabase().execSQL("VACUUM;");
} else
Log.w("Insufficient space for VACUUM");
}
} catch (Throwable ex) {