Fixed orphan messages (2)

pull/209/head
M66B 2 years ago
parent 86c524c7c6
commit 457ea09fa3

File diff suppressed because it is too large Load Diff

@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 247, version = 248,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -2481,13 +2481,17 @@ public abstract class DB extends RoomDatabase {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion); logMigration(startVersion, endVersion);
EntityMessage.convert(context, true);
} }
}).addMigrations(new Migration(246, 247) { }).addMigrations(new Migration(246, 247) {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion); logMigration(startVersion, endVersion);
EntityMessage.convert(context, false); }
}).addMigrations(new Migration(247, 248) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
EntityMessage.convert(context);
} }
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {
@Override @Override

@ -578,26 +578,21 @@ public class EntityMessage implements Serializable {
static File getFile(Context context, Long id) { static File getFile(Context context, Long id) {
File root = new File(context.getFilesDir(), "messages"); File root = new File(context.getFilesDir(), "messages");
File dir = Helper.ensureExists(new File(root, Long.toString(id / 1000))); File dir = Helper.ensureExists(new File(root, "D" + (id / 1000)));
return new File(dir, id.toString()); return new File(dir, id.toString());
} }
static void convert(Context context, boolean silent) { static void convert(Context context) {
File root = new File(context.getFilesDir(), "messages"); File root = new File(context.getFilesDir(), "messages");
File[] files = root.listFiles(); List<File> files = Helper.listFiles(root);
if (files == null)
return;
for (File file : files) for (File file : files)
if (file.isFile()) if (file.isFile())
try { try {
long id = Long.parseLong(file.getName()); long id = Long.parseLong(file.getName());
File target = getFile(context, id); File target = getFile(context, id);
Helper.copy(file, target); if (!file.renameTo(target))
file.delete(); throw new IllegalArgumentException("Failed moving " + file);
} catch (Throwable ex) { } catch (Throwable ex) {
if (silent)
Log.i(ex);
else
Log.e(ex); Log.e(ex);
} }
} }

Loading…
Cancel
Save