fix(library): reset checkpoints and artwork on forced full scans

This commit is contained in:
zarzet
2026-09-15 21:44:53 +07:00
parent 097af1532f
commit 0ad17f0caa
3 changed files with 158 additions and 0 deletions
@@ -522,15 +522,18 @@ class LocalLibraryNotifier extends Notifier<LocalLibraryState> {
required String sourceId,
required String folderPath,
required bool isSaf,
required bool forceFullScan,
}) async {
if (_scanCancelRequested) return null;
final scanFile = isSaf
? await PlatformBridge.scanSafTreeToNDJSONFile(
folderPath,
forceFullScan: forceFullScan,
isCancelled: () => _scanCancelRequested,
)
: await PlatformBridge.scanLibraryFolderToNDJSONFile(
folderPath,
forceFullScan: forceFullScan,
isCancelled: () => _scanCancelRequested,
);
var ingested = false;
@@ -677,6 +680,7 @@ class LocalLibraryNotifier extends Notifier<LocalLibraryState> {
sourceId: activeSourceId,
folderPath: effectiveFolderPath,
isSaf: isSaf,
forceFullScan: forceFullScan,
);
if (scanResult == null || _scanCancelRequested) {
state = state.copyWith(
+20
View File
@@ -2193,11 +2193,13 @@ class PlatformBridge {
static Future<LibraryScanNDJSONFile> scanLibraryFolderToNDJSONFile(
String folderPath, {
bool forceFullScan = false,
bool Function()? isCancelled,
}) {
return _scanToNDJSONFile(
method: 'scanLibraryFolderToNDJSONFile',
arguments: {'folder_path': folderPath},
forceFullScan: forceFullScan,
isCancelled: isCancelled,
);
}
@@ -2239,11 +2241,13 @@ class PlatformBridge {
static Future<LibraryScanNDJSONFile> scanSafTreeToNDJSONFile(
String treeUri, {
bool forceFullScan = false,
bool Function()? isCancelled,
}) {
return _scanToNDJSONFile(
method: 'scanSafTreeToNDJSONFile',
arguments: {'tree_uri': treeUri},
forceFullScan: forceFullScan,
isCancelled: isCancelled,
);
}
@@ -2251,6 +2255,7 @@ class PlatformBridge {
static Future<LibraryScanNDJSONFile> _scanToNDJSONFile({
required String method,
required Map<String, dynamic> arguments,
required bool forceFullScan,
bool Function()? isCancelled,
}) async {
// Stable support-directory path lets native SAF scans resume after process death.
@@ -2270,6 +2275,21 @@ class PlatformBridge {
'library_scan_${hash.toRadixString(16).padLeft(8, '0')}.ndjson',
);
try {
if (isCancelled?.call() == true) {
throw StateError('Library scan cancelled before native scan');
}
if (forceFullScan) {
// An explicit rescan must not resume metadata from an earlier attempt.
for (final file in [output, File('${output.path}.state')]) {
if (await file.exists()) await file.delete();
}
// Preserve covers referenced by the current DB until ingestion succeeds.
// Fresh paths bypass native disk and Flutter image caches together.
final covers = Directory('${scanDir.path}/library_covers');
await covers.create(recursive: true);
final freshCovers = await covers.createTemp('full_scan_');
await setLibraryCoverCacheDir(freshCovers.path);
}
if (isCancelled?.call() == true) {
throw StateError('Library scan cancelled before native scan');
}