perf(library): page missing-file cleanup with safe SAF batch checks

This commit is contained in:
zarzet
2026-09-06 02:34:49 +07:00
parent 90d3a5e3de
commit 62ef538690
8 changed files with 456 additions and 54 deletions
+15 -1
View File
@@ -8,6 +8,7 @@ import 'package:spotiflac_android/services/library_database.dart';
import 'package:spotiflac_android/services/notification_service.dart';
import 'package:spotiflac_android/services/platform_bridge.dart';
import 'package:spotiflac_android/utils/logger.dart';
import 'package:spotiflac_android/utils/file_access.dart';
import 'package:spotiflac_android/utils/local_library_scan_prefs.dart';
import 'package:spotiflac_android/utils/progress_stream_poller.dart';
@@ -1143,7 +1144,20 @@ class LocalLibraryNotifier extends Notifier<LocalLibraryState> {
);
if (securityAccess == null) continue;
}
removed += await _db.cleanupMissingFiles(sourceId: source.id);
removed += await _db.cleanupMissingFiles(
sourceId: source.id,
canDelete: () async {
if (isContentUri(source.path)) {
return PlatformBridge.isSafTreeAccessible(source.path);
}
// Recheck access after the file probes, before deleting a page.
// An empty but readable source is valid; an offline one throws.
await Directory(
securityAccess?.path ?? source.path,
).list(followLinks: false).take(1).drain<void>();
return true;
},
);
} finally {
if (securityAccess != null) {
await PlatformBridge.stopAccessingIosBookmark(securityAccess);