fix(database): swallow legacy documents lookup failures
This commit is contained in:
@@ -663,13 +663,18 @@ Future<void> migrateLegacyDesktopDatabase({
|
||||
Future<void> Function(File source, String targetPath)? renameOverride,
|
||||
}) async {
|
||||
final File oldFile;
|
||||
if (sourceOverride != null) {
|
||||
oldFile = sourceOverride;
|
||||
} else {
|
||||
final oldFolder = await getApplicationDocumentsDirectory();
|
||||
oldFile = File(p.join(oldFolder.path, 'plezy_downloads.db'));
|
||||
try {
|
||||
if (sourceOverride != null) {
|
||||
oldFile = sourceOverride;
|
||||
} else {
|
||||
final oldFolder = await getApplicationDocumentsDirectory();
|
||||
oldFile = File(p.join(oldFolder.path, 'plezy_downloads.db'));
|
||||
}
|
||||
if (!await oldFile.exists()) return;
|
||||
} catch (e, st) {
|
||||
appLogger.w('Legacy DB migration skipped before source lookup completed', error: e, stackTrace: st);
|
||||
return;
|
||||
}
|
||||
if (!await oldFile.exists()) return;
|
||||
|
||||
try {
|
||||
if (renameOverride != null) {
|
||||
|
||||
@@ -4,9 +4,11 @@ import 'package:plezy/media/ids.dart';
|
||||
import 'package:drift/drift.dart' hide isNull, isNotNull;
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
|
||||
import 'package:plezy/database/app_database.dart';
|
||||
import 'package:plezy/database/download_operations.dart';
|
||||
import 'package:plezy/models/download_models.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
void main() {
|
||||
final suite = _AppDatabaseTestSuite();
|
||||
@@ -234,6 +236,20 @@ class _AppDatabaseTestSuite {
|
||||
expect(await source.readAsBytes(), [0xAA, 0xBB]);
|
||||
expect(await target.exists(), isFalse);
|
||||
});
|
||||
|
||||
test('documents directory lookup failure is a silent no-op', () async {
|
||||
final previousPathProvider = PathProviderPlatform.instance;
|
||||
final target = File('${tempDir.path}/AppData/plezy_downloads.db');
|
||||
PathProviderPlatform.instance = _ThrowingDocumentsPathProvider();
|
||||
|
||||
try {
|
||||
await expectLater(migrateLegacyDesktopDatabase(target: target), completes);
|
||||
} finally {
|
||||
PathProviderPlatform.instance = previousPathProvider;
|
||||
}
|
||||
|
||||
expect(await target.exists(), isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1029,3 +1045,8 @@ class _AppDatabaseTestSuite {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _ThrowingDocumentsPathProvider extends PathProviderPlatform with MockPlatformInterfaceMixin {
|
||||
@override
|
||||
Future<String?> getApplicationDocumentsPath() async => throw Exception('documents unavailable');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user