From ab2f8cf6ff50efc1a2eddba3e557a868d0090db2 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:39:17 +0100 Subject: [PATCH] fix: normalize corrupted download paths on startup --- lib/services/download_manager_service.dart | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/services/download_manager_service.dart b/lib/services/download_manager_service.dart index cff9e81b..4e6ac70e 100644 --- a/lib/services/download_manager_service.dart +++ b/lib/services/download_manager_service.dart @@ -309,9 +309,33 @@ class DownloadManagerService { appLogger.i('Rescheduled ${rescheduled.length} killed download task(s)'); } + // One-time migration: normalize stored file paths that may contain a + // doubled base-dir prefix from an earlier bug in the recovery callback. + final prefs = (await SettingsService.getInstance()).prefs; + if (!(prefs.getBool('download_paths_normalized') ?? false)) { + final allItems = await _database.select(_database.downloadedMedia).get(); + var fixed = 0; + for (final item in allItems) { + if (item.videoFilePath != null) { + final normalized = await _storageService.toRelativePath(item.videoFilePath!); + if (normalized != item.videoFilePath) { + await _database.updateVideoFilePath(item.globalKey, normalized); + fixed++; + } + } + if (item.thumbPath != null) { + final normalized = await _storageService.toRelativePath(item.thumbPath!); + if (normalized != item.thumbPath) { + await _database.updateArtworkPaths(globalKey: item.globalKey, thumbPath: normalized); + } + } + } + if (fixed > 0) appLogger.i('Normalized $fixed corrupted download path(s)'); + await prefs.setBool('download_paths_normalized', true); + } + // Scan drift for orphaned items stuck in 'downloading' final allDownloads = await _database.select(_database.downloadedMedia).get(); - for (final item in allDownloads) { if (item.status == DownloadStatus.downloading.index) { // Video already downloaded but post-processing didn't complete