refactor: remove old layout migration code

This commit is contained in:
Moustapha Kodjo Amadou 2025-11-25 16:51:49 +01:00
parent c2a1e5ee17
commit b6eb5f2f3f

View file

@ -76,7 +76,6 @@ void main(List<String> args) async {
}
final storage = StorageProvider();
await storage.requestPermission();
await _migrateOldLayout();
isar = await storage.initDB(null, inspector: kDebugMode);
runApp(ProviderScope(child: MyApp(), retry: (retryCount, error) => null));
unawaited(_postLaunchInit(storage)); // Defer non-essential async operations
@ -96,62 +95,6 @@ Future<void> _postLaunchInit(StorageProvider storage) async {
await storage.deleteBtDirectory();
}
/// This can be removed after next release (v0.6.40?)
/// It is a one-time thing to migrate the database and folders to the new
/// iOS and macOS location (PR #517)
Future<void> _migrateOldLayout() async {
if (!(Platform.isIOS || Platform.isMacOS)) return;
final root = await getApplicationDocumentsDirectory();
final rootM = Directory(p.join(root.path, 'Mangayomi'));
if (Platform.isIOS) {
await _migrateOld(rootM, root);
} else {
await _migrateOld(root, rootM);
}
}
Future<void> _migrateOld(Directory oldRoot, Directory root) async {
if (!await oldRoot.exists()) return;
final newDbDir = Directory(p.join(root.path, 'databases'));
await newDbDir.create(recursive: true);
// Move database files to new directory
for (final filename in [
'mangayomiDb.isar',
'mangayomiDb.isar.lock',
'tracker_library.hive',
'tracker_library.lock',
]) {
final oldFile = File(p.join(root.path, filename));
if (await oldFile.exists()) {
final newFile = File(p.join(newDbDir.path, filename));
await oldFile.rename(newFile.path);
}
}
// Move subfolders up a level
for (final sub in ['backup', 'downloads', 'Pictures', 'local']) {
final oldSubDir = Directory(p.join(oldRoot.path, sub));
final newSubDir = Directory(p.join(root.path, sub));
if (!await oldSubDir.exists()) continue;
// If by chance newSubDir is empty, safe to rename; otherwise, move contents
if (!(await newSubDir.exists())) {
await oldSubDir.rename(newSubDir.path);
} else {
// merge contents
await for (final entity in oldSubDir.list()) {
await entity.rename(p.join(newSubDir.path, p.basename(entity.path)));
}
}
// remove subfolder if empty
if (await oldSubDir.exists() && await oldSubDir.list().isEmpty) {
await oldSubDir.delete();
}
}
// Clean up old empty folder
if (await oldRoot.exists() && await oldRoot.list().isEmpty) {
await oldRoot.delete();
}
}
class MyApp extends ConsumerStatefulWidget {
const MyApp({super.key});